]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/cgroup-util.c
cgroup-util: be more strict when processing slice unit names
[thirdparty/systemd.git] / src / shared / cgroup-util.c
index 1306cc197a21b5bee4989462506997ee4f831ccc..b5e4094f4ebe578aecbbd886bc54be85bda9a773 100644 (file)
@@ -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");