summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-30 19:42:48 +0200
committerLennart Poettering <lennart@poettering.net>2015-05-05 15:06:33 -0700
commite66e5b612a9e5921d79a6aedab4983e33dff8cb1 (patch)
tree87085e08c4c4b06772f001d871afdc643cf0d3d6
parent32fea77178ff9aaa09a7b043965fce854fdf8874 (diff)
cgroup-util: be more strict when processing slice unit names
-rw-r--r--src/shared/cgroup-util.c8
-rw-r--r--src/test/test-cgroup-util.c2
2 files changed, 8 insertions, 2 deletions
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index 1306cc197..b5e4094f4 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -1663,11 +1663,17 @@ int cg_slice_to_path(const char *unit, char **ret) {
return -ENOMEM;
dash = strchr(p, '-');
+
+ /* Don't allow initial dashes */
+ if (dash == p)
+ return -EINVAL;
+
while (dash) {
_cleanup_free_ char *escaped = NULL;
char n[dash - p + sizeof(".slice")];
- if (isempty(dash + 1))
+ /* Don't allow trailing or double dashes */
+ if (dash[1] == 0 || dash[1] == '-')
return -EINVAL;
strcpy(stpncpy(n, p, dash - p), ".slice");
diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c
index efe99cb34..4a89f6451 100644
--- a/src/test/test-cgroup-util.c
+++ b/src/test/test-cgroup-util.c
@@ -274,7 +274,7 @@ static void test_slice_to_path(void) {
test_slice_to_path_one("-foo-.slice", NULL, -EINVAL);
test_slice_to_path_one("-foo.slice", NULL, -EINVAL);
test_slice_to_path_one("foo-.slice", NULL, -EINVAL);
- test_slice_to_path_one("foo--bar.slice", "foo.slice/foo-.slice/foo--bar.slice", 0);
+ test_slice_to_path_one("foo--bar.slice", NULL, -EINVAL);
test_slice_to_path_one("foo.slice/foo--bar.slice", NULL, -EINVAL);
test_slice_to_path_one("a-b.slice", "a.slice/a-b.slice", 0);
test_slice_to_path_one("a-b-c-d-e.slice", "a.slice/a-b.slice/a-b-c.slice/a-b-c-d.slice/a-b-c-d-e.slice", 0);