From: Lennart Poettering Date: Thu, 30 Apr 2015 17:44:10 +0000 (+0200) Subject: util: be a bit safer in path_is_safe() X-Git-Tag: v226.4~1^2~408 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=3a296a5fe6c06deb497b09ab29b8363761b2885d util: be a bit safer in path_is_safe() We should be more strict when verifying paths with path_is_safe() for potentially dangerous constructs, and that includes lengths of PATH_MAX-1 and larger. Be more accurate here. --- diff --git a/src/shared/util.c b/src/shared/util.c index 693bb1d9a..f904d0325 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -3918,7 +3918,7 @@ bool path_is_safe(const char *p) { if (streq(p, "..") || startswith(p, "../") || endswith(p, "/..") || strstr(p, "/../")) return false; - if (strlen(p) > PATH_MAX) + if (strlen(p)+1 > PATH_MAX) return false; /* The following two checks are not really dangerous, but hey, they still are confusing */