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");
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);