]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
chase: fix CHASE_STEP with ".."
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 20 Jul 2023 06:04:01 +0000 (15:04 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 29 Jul 2023 12:58:29 +0000 (21:58 +0900)
src/basic/chase.c

index 2db0b412618bff85846d2a1a2cddee78d270a847..8f9c361a098d08cebe15e7a18925869d6aac0fe8 100644 (file)
@@ -264,8 +264,11 @@ int chaseat(int dir_fd, const char *path, ChaseFlags flags, char **ret_path, int
 
                         /* If we already are at the top, then going up will not change anything. This is
                          * in-line with how the kernel handles this. */
-                        if (empty_or_root(done) && FLAGS_SET(flags, CHASE_AT_RESOLVE_IN_ROOT))
+                        if (empty_or_root(done) && FLAGS_SET(flags, CHASE_AT_RESOLVE_IN_ROOT)) {
+                                if (FLAGS_SET(flags, CHASE_STEP))
+                                        goto chased_one;
                                 continue;
+                        }
 
                         fd_parent = openat(fd, "..", O_CLOEXEC|O_NOFOLLOW|O_PATH|O_DIRECTORY);
                         if (fd_parent < 0)
@@ -281,8 +284,11 @@ int chaseat(int dir_fd, const char *path, ChaseFlags flags, char **ret_path, int
                                 r = dir_fd_is_root(fd);
                                 if (r < 0)
                                         return r;
-                                if (r > 0)
+                                if (r > 0) {
+                                        if (FLAGS_SET(flags, CHASE_STEP))
+                                                goto chased_one;
                                         continue;
+                                }
                         }
 
                         r = path_extract_directory(done, &parent);