mirror of
https://github.com/systemd/systemd.git
synced 2026-11-06 05:17:24 +00:00
tree-wide: use path_implies_directory() instead of checking for a trailing slash
A path that ends in a slash must refer to a directory, but so must one whose last component is "." or "..". We have path_implies_directory() covering all these cases, hence use it where we so far just checked for a trailing slash, to determine whether a path can only refer to a directory. This affects valid_shell() and valid_device_node_path() (no change in behavior there, since the paths are refused anyway if not normalized), and the check in the boot loader spec parser that refuses paths to directories (where "/foo/." so far slipped through).
This commit is contained in:
1 parent
67ffd130ea
commit
7c6c0851f1
3 files changed
+4
-4
No files matched your search
@@ -1308,7 +1308,7 @@ bool valid_device_node_path(const char *path) {
|
||||
if (!PATH_STARTSWITH_SET(path, "/dev/", "/run/systemd/inaccessible/"))
|
||||
return false;
|
||||
|
||||
if (endswith(path, "/")) /* can't be a device node if it ends in a slash */
|
||||
if (path_implies_directory(path)) /* can't be a device node if it must be a directory */
|
||||
return false;
|
||||
|
||||
return path_is_normalized(path);
|
||||
|
||||
@@ -915,7 +915,7 @@ bool valid_shell(const char *p) {
|
||||
if (!valid_home(p))
|
||||
return false;
|
||||
|
||||
return !endswith(p, "/"); /* one additional restriction: shells may not be dirs */
|
||||
return !path_implies_directory(p); /* one additional restriction: shells may not be dirs */
|
||||
}
|
||||
|
||||
int maybe_setgroups(size_t size, const gid_t *list) {
|
||||
|
||||
@@ -172,8 +172,8 @@ static int mangle_path(
|
||||
return -ENOMEM;
|
||||
|
||||
/* We only reference files, never directories */
|
||||
if (endswith(c, "/")) {
|
||||
log_syntax(NULL, LOG_WARNING, fname, line, 0, "Path in field '%s' has trailing slash, ignoring: %s", field, c);
|
||||
if (path_implies_directory(c)) {
|
||||
log_syntax(NULL, LOG_WARNING, fname, line, 0, "Path in field '%s' refers to a directory, ignoring: %s", field, c);
|
||||
*ret = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user