summaryrefslogtreecommitdiff
path: root/src/basic/path-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-02-01 22:43:28 -0500
committerGitHub <noreply@github.com>2017-02-01 22:43:28 -0500
commitf7dda6c625c7b12a1d4635a679e442250a0f69f0 (patch)
tree9f585f8d382e8a388b06711caf418fcfe5ee6abe /src/basic/path-util.c
parentef2f4f911b6a6499db4468570ed868add45b3069 (diff)
parent9ff233dc1fa2f47fc4499a12a8ee0640aba30657 (diff)
Merge pull request #5203 from poettering/dotdot
trivial unification of checking for "." and ".." when iterating through directories...
Diffstat (limited to 'src/basic/path-util.c')
-rw-r--r--src/basic/path-util.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/basic/path-util.c b/src/basic/path-util.c
index 9a51e0d8bc..1313a52c9c 100644
--- a/src/basic/path-util.c
+++ b/src/basic/path-util.c
@@ -699,10 +699,7 @@ bool filename_is_valid(const char *p) {
if (isempty(p))
return false;
- if (streq(p, "."))
- return false;
-
- if (streq(p, ".."))
+ if (dot_or_dot_dot(p))
return false;
e = strchrnul(p, '/');
@@ -720,14 +717,17 @@ bool path_is_safe(const char *p) {
if (isempty(p))
return false;
- if (streq(p, "..") || startswith(p, "../") || endswith(p, "/..") || strstr(p, "/../"))
+ if (dot_or_dot_dot(p))
+ return false;
+
+ if (startswith(p, "../") || endswith(p, "/..") || strstr(p, "/../"))
return false;
if (strlen(p)+1 > PATH_MAX)
return false;
/* The following two checks are not really dangerous, but hey, they still are confusing */
- if (streq(p, ".") || startswith(p, "./") || endswith(p, "/.") || strstr(p, "/./"))
+ if (startswith(p, "./") || endswith(p, "/.") || strstr(p, "/./"))
return false;
if (strstr(p, "//"))
@@ -892,3 +892,16 @@ int systemd_installation_has_version(const char *root, unsigned minimal_version)
return false;
}
+
+bool dot_or_dot_dot(const char *path) {
+ if (!path)
+ return false;
+ if (path[0] != '.')
+ return false;
+ if (path[1] == 0)
+ return true;
+ if (path[1] != '.')
+ return false;
+
+ return path[2] == 0;
+}