From 5f0bae7bffa8fe334dfef957d8eb48fc643e47ae Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 20 Jul 2023 15:04:01 +0900 Subject: [PATCH] chase: fix CHASE_STEP with ".." --- src/basic/chase.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/basic/chase.c b/src/basic/chase.c index 2db0b412618..8f9c361a098 100644 --- a/src/basic/chase.c +++ b/src/basic/chase.c @@ -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); -- 2.47.3