From 66368835643883e2a058b847c6520845c76f6173 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 1 May 2021 02:30:15 +0900 Subject: path-util: use path_find_first_component() in path_is_valid() --- src/basic/path-util.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'src/basic/path-util.c') diff --git a/src/basic/path-util.c b/src/basic/path-util.c index ed4fbcca23..752590bf70 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; } } -- cgit v1.2.1