From 296acffe45a74a8c9cca393494760169b5a4afd3 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Fri, 7 Dec 2018 16:12:19 +0100 Subject: When parsing paths, reject anything above PATH_MAX The check for length is done after path_simplify(), to be nice to paths which are constructed using specifiers, and have duplicate slashes and stuff. --- src/basic/path-util.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/basic') diff --git a/src/basic/path-util.c b/src/basic/path-util.c index 995f39f16..221517303 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -1139,5 +1139,12 @@ int path_simplify_and_warn( return -EINVAL; } + if (!path_is_valid(path)) { + log_syntax(unit, LOG_ERR, filename, line, 0, + "%s= path has invalid length (%zu bytes)%s.", + lvalue, strlen(path), fatal ? "" : ", ignoring"); + return -EINVAL; + } + return 0; } -- cgit v1.2.3-65-gdbad From f8703ed7e51121cd42bfb05fe9fe2a626118b07b Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Fri, 7 Dec 2018 16:16:39 +0100 Subject: basic/path-util: line-break PATH_FOREACH_PREFIX macros Now I can see what they do :] --- src/basic/path-util.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/basic') diff --git a/src/basic/path-util.h b/src/basic/path-util.h index 78db41b85..094aa47c0 100644 --- a/src/basic/path-util.h +++ b/src/basic/path-util.h @@ -97,12 +97,24 @@ int mkfs_exists(const char *fstype); /* Iterates through the path prefixes of the specified path, going up * the tree, to root. Also returns "" (and not "/"!) for the root * directory. Excludes the specified directory itself */ -#define PATH_FOREACH_PREFIX(prefix, path) \ - for (char *_slash = ({ path_simplify(strcpy(prefix, path), false); streq(prefix, "/") ? NULL : strrchr(prefix, '/'); }); _slash && ((*_slash = 0), true); _slash = strrchr((prefix), '/')) +#define PATH_FOREACH_PREFIX(prefix, path) \ + for (char *_slash = ({ \ + path_simplify(strcpy(prefix, path), false); \ + streq(prefix, "/") ? NULL : strrchr(prefix, '/'); \ + }); \ + _slash && ((*_slash = 0), true); \ + _slash = strrchr((prefix), '/')) /* Same as PATH_FOREACH_PREFIX but also includes the specified path itself */ -#define PATH_FOREACH_PREFIX_MORE(prefix, path) \ - for (char *_slash = ({ path_simplify(strcpy(prefix, path), false); if (streq(prefix, "/")) prefix[0] = 0; strrchr(prefix, 0); }); _slash && ((*_slash = 0), true); _slash = strrchr((prefix), '/')) +#define PATH_FOREACH_PREFIX_MORE(prefix, path) \ + for (char *_slash = ({ \ + path_simplify(strcpy(prefix, path), false); \ + if (streq(prefix, "/")) \ + prefix[0] = 0; \ + strrchr(prefix, 0); \ + }); \ + _slash && ((*_slash = 0), true); \ + _slash = strrchr((prefix), '/')) char *prefix_root(const char *root, const char *path); -- cgit v1.2.3-65-gdbad