]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
chase: use dir_fd_is_root() to check if fd points to the root directory
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 10 Apr 2023 00:55:22 +0000 (09:55 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 10 Apr 2023 00:55:29 +0000 (09:55 +0900)
As commented in dir_fd_is_root(), comparing inode is not enough to
determine if we are at the root directory.

src/basic/chase.c

index b8441aa28bbebf983f8aeefe7b4d2b509744ca78..f62c317026a61accccfd4419acdc18dd6190f991 100644 (file)
@@ -262,10 +262,16 @@ int chaseat(int dir_fd, const char *path, ChaseFlags flags, char **ret_path, int
                         if (fstat(fd_parent, &st_parent) < 0)
                                 return -errno;
 
-                        /* If we opened the same directory, that means we're at the host root directory, so
+                        /* If we opened the same directory, that _may_ indicate that we're at the host root
+                         * directory. Let's confirm that in more detail with dir_fd_is_root(). And if so,
                          * going up won't change anything. */
-                        if (stat_inode_same(&st_parent, &st))
-                                continue;
+                        if (stat_inode_same(&st_parent, &st)) {
+                                r = dir_fd_is_root(fd);
+                                if (r < 0)
+                                        return r;
+                                if (r > 0)
+                                        continue;
+                        }
 
                         r = path_extract_directory(done, &parent);
                         if (r >= 0 || r == -EDESTADDRREQ)