]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tmpfile: always get file descriptor of root or current directory 19857/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 9 Jun 2021 04:33:34 +0000 (13:33 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 9 Jun 2021 20:42:03 +0000 (05:42 +0900)
Fixes CID#1457467.

src/tmpfiles/tmpfiles.c

index 527ff5d49c600c59852dda6f1cb98dccaacd4545..8e8be8472858295f5818b70e403ded358aafe490 100644 (file)
@@ -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");