diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-06-09 13:33:34 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-06-10 05:42:03 +0900 |
commit | c68cafbabef61afed9d95b15a37eedb1e8577577 (patch) | |
tree | 22b51c9beab4e9c2edc3e81401bafd21f359c053 /src/tmpfiles | |
parent | 21e43a7c51ff5bc560e67e95f24fc1589d4e02a2 (diff) | |
download | systemd-c68cafbabef61afed9d95b15a37eedb1e8577577.tar.gz |
tmpfile: always get file descriptor of root or current directory
Fixes CID#1457467.
Diffstat (limited to 'src/tmpfiles')
-rw-r--r-- | src/tmpfiles/tmpfiles.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 527ff5d49c..8e8be84728 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -2129,12 +2129,10 @@ static int mkdir_parents_rm_if_wrong_type(mode_t child_mode, const char *path) { "Trailing path separators are only allowed if child_mode is not set; got \"%s\"", path); /* Get the parent_fd and stat. */ - parent_fd = AT_FDCWD; - if (path_is_absolute(path)) { - parent_fd = open("/", O_NOCTTY | O_CLOEXEC | O_DIRECTORY); - if (parent_fd < 0) - return log_error_errno(errno, "Failed to open root: %m"); - } + parent_fd = openat(AT_FDCWD, path_is_absolute(path) ? "/" : ".", O_NOCTTY | O_CLOEXEC | O_DIRECTORY); + if (parent_fd < 0) + return log_error_errno(errno, "Failed to open root: %m"); + if (fstat(parent_fd, &parent_st) < 0) return log_error_errno(errno, "Failed to stat root: %m"); |