diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-12-10 15:50:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-10 15:50:08 +0100 |
commit | 8f3fd07ac0407561a4d760e585913ba51e38b828 (patch) | |
tree | abf6759a8e8b900501ae2e940e1bed32a8069712 /src/basic | |
parent | network: fix handling of uninitialized and zero IAID setting (diff) | |
parent | fuzz-unit-file: add one more test case (diff) | |
download | systemd-8f3fd07ac0407561a4d760e585913ba51e38b828.tar.gz systemd-8f3fd07ac0407561a4d760e585913ba51e38b828.tar.bz2 systemd-8f3fd07ac0407561a4d760e585913ba51e38b828.zip |
Merge pull request #11105 from keszybz/path-parsing
Some tightening of our path parsing code
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/path-util.c | 7 | ||||
-rw-r--r-- | src/basic/path-util.h | 20 |
2 files changed, 23 insertions, 4 deletions
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; } 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); |