X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbasic%2Fpath-util.c;fp=src%2Fbasic%2Fpath-util.c;h=05384c26b619b8a86beb6207ce1eb55ee5e17a06;hb=321384507f1223033fc0fb2969f6e29598ba7d92;hp=84f327d7d050fbd4a6c1e98d21a6fb38316533a8;hpb=de3f86951e5c91756ea9d9b5c9e381b6f293a3be;p=elogind.git diff --git a/src/basic/path-util.c b/src/basic/path-util.c index 84f327d7d..05384c26b 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -703,10 +703,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, '/'); @@ -724,14 +721,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, "//")) @@ -898,3 +898,16 @@ int systemd_installation_has_version(const char *root, unsigned minimal_version) return false; } #endif // 0 + +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; +}