]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup-util: use path_find_first_component where appropriate
authorMike Yuan <me@yhndnzj.com>
Thu, 21 Mar 2024 10:29:07 +0000 (18:29 +0800)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 21 Mar 2024 23:00:55 +0000 (08:00 +0900)
Prompted by 8922a728f732a716ecd17dd67cd39bc1a0fc4aa5

src/basic/cgroup-util.c

index 60b4e3f22691740e33cd5b4e3df7bf84172613e8..6991460f86e65a0b7b9a30293f6c71bba8025da6 100644 (file)
@@ -1500,22 +1500,25 @@ int cg_path_get_slice(const char *p, char **ret_slice) {
         assert(p);
         assert(ret_slice);
 
-        /* Finds the right-most slice unit from the beginning, but
-         * stops before we come to the first non-slice unit. */
+        /* Finds the right-most slice unit from the beginning, but stops before we come to
+         * the first non-slice unit. */
 
         for (;;) {
-                p += strspn(p, "/");
+                const char *s;
+                int n;
 
-                size_t n = strcspn(p, "/");
-                if (!valid_slice_name(p, n))
+                n = path_find_first_component(&p, /* accept_dot_dot = */ false, &s);
+                if (n < 0)
+                        return n;
+                if (!valid_slice_name(s, n))
                         break;
 
-                e = p;
-                p += n;
+                e = s;
         }
 
         if (e)
                 return cg_path_decode_unit(e, ret_slice);
+
         return strdup_to(ret_slice, SPECIAL_ROOT_SLICE);
 }