From: Yu Watanabe Date: Fri, 30 Apr 2021 17:30:15 +0000 (+0900) Subject: path-util: use path_find_first_component() in path_is_valid() X-Git-Tag: v249-rc1~131^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=66368835643883e2a058b847c6520845c76f6173;p=thirdparty%2Fsystemd.git path-util: use path_find_first_component() in path_is_valid() --- diff --git a/src/basic/path-util.c b/src/basic/path-util.c index ed4fbcca235..752590bf70a 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -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; } }