summaryrefslogtreecommitdiffstats
path: root/src/basic/path-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-04-30 19:30:15 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-05-28 06:41:23 +0200
commit66368835643883e2a058b847c6520845c76f6173 (patch)
treea282bbb7bf137fc37971b724f04eb3410f323bd0 /src/basic/path-util.c
parentpath-util: introduce path_find_first_component() (diff)
downloadsystemd-66368835643883e2a058b847c6520845c76f6173.tar.xz
systemd-66368835643883e2a058b847c6520845c76f6173.zip
path-util: use path_find_first_component() in path_is_valid()
Diffstat (limited to 'src/basic/path-util.c')
-rw-r--r--src/basic/path-util.c17
1 files changed, 5 insertions, 12 deletions
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;
}
}