]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
path-util: use path_find_first_component() in path_is_valid()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 30 Apr 2021 17:30:15 +0000 (02:30 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 28 May 2021 04:41:23 +0000 (13:41 +0900)
src/basic/path-util.c

index ed4fbcca2359b4dcaabf5d160193a1d453492f12..752590bf70ad68371d8a7b82a9f48b06a21d87ff 100644 (file)
@@ -1038,28 +1038,21 @@ bool filename_is_valid(const char *p) {
 }
 
 bool path_is_valid(const char *p) {
-
         if (isempty(p))
                 return false;
 
         for (const char *e = p;;) {
-                size_t n;
+                int r;
+
+                r = path_find_first_component(&e, /* accept_dot_dot= */ true, NULL);
+                if (r < 0)
+                        return false;
 
-                /* Skip over slashes */
-                e += strspn(e, "/");
                 if (e - p >= PATH_MAX) /* Already reached the maximum length for a path? (PATH_MAX is counted
                                         * *with* the trailing NUL byte) */
                         return false;
                 if (*e == 0)           /* End of string? Yay! */
                         return true;
-
-                /* Skip over one component */
-                n = strcspn(e, "/");
-                if (n > NAME_MAX)      /* One component larger than NAME_MAX? (NAME_MAX is counted *without* the
-                                        * trailing NUL byte) */
-                        return false;
-
-                e += n;
         }
 }