summaryrefslogtreecommitdiff
path: root/src/shared/cgroup-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-30 20:21:00 +0200
committerLennart Poettering <lennart@poettering.net>2015-05-05 15:06:42 -0700
commit7410616cd9dbbec97cf98d75324da5cda2b2f7a2 (patch)
tree6d968995b3bdf961603ab4853bf078c0dbdce27c /src/shared/cgroup-util.c
parent6442185ab674cc202d63c18605057b9a51ca2722 (diff)
core: rework unit name validation and manipulation logic
A variety of changes: - Make sure all our calls distuingish OOM from other errors if OOM is not the only error possible. - Be much stricter when parsing escaped paths, do not accept trailing or leading escaped slashes. - Change unit validation to take a bit mask for allowing plain names, instance names or template names or an combination thereof. - Refuse manipulating invalid unit name
Diffstat (limited to 'src/shared/cgroup-util.c')
-rw-r--r--src/shared/cgroup-util.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index b5e4094f4e..c0b0ca4cf2 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -1154,7 +1154,7 @@ int cg_path_decode_unit(const char *cgroup, char **unit){
c = strndupa(cgroup, n);
c = cg_unescape(c);
- if (!unit_name_is_valid(c, TEMPLATE_INVALID))
+ if (!unit_name_is_valid(c, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE))
return -ENXIO;
s = strdup(c);
@@ -1181,7 +1181,7 @@ static bool valid_slice_name(const char *p, size_t n) {
c = cg_unescape(buf);
- return unit_name_is_valid(c, TEMPLATE_INVALID);
+ return unit_name_is_valid(c, UNIT_NAME_PLAIN);
}
return false;
@@ -1638,6 +1638,7 @@ bool cg_controller_is_valid(const char *p, bool allow_named) {
int cg_slice_to_path(const char *unit, char **ret) {
_cleanup_free_ char *p = NULL, *s = NULL, *e = NULL;
const char *dash;
+ int r;
assert(unit);
assert(ret);
@@ -1652,15 +1653,15 @@ int cg_slice_to_path(const char *unit, char **ret) {
return 0;
}
- if (!unit_name_is_valid(unit, TEMPLATE_INVALID))
+ if (!unit_name_is_valid(unit, UNIT_NAME_PLAIN))
return -EINVAL;
if (!endswith(unit, ".slice"))
return -EINVAL;
- p = unit_name_to_prefix(unit);
- if (!p)
- return -ENOMEM;
+ r = unit_name_to_prefix(unit, &p);
+ if (r < 0)
+ return r;
dash = strchr(p, '-');
@@ -1677,7 +1678,7 @@ int cg_slice_to_path(const char *unit, char **ret) {
return -EINVAL;
strcpy(stpncpy(n, p, dash - p), ".slice");
- if (!unit_name_is_valid(n, TEMPLATE_INVALID))
+ if (!unit_name_is_valid(n, UNIT_NAME_PLAIN))
return -EINVAL;
escaped = cg_escape(n);