From: Yu Watanabe Date: Thu, 30 Mar 2023 04:15:59 +0000 (+0900) Subject: chase: drop CHASE_AT_RESOLVE_IN_ROOT when AT_FDCWD or root dir fd is specified X-Git-Tag: v254-rc1~863^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e115daa6a8f0cc80591228e4c6f651b9afc66b30;p=thirdparty%2Fsystemd.git chase: drop CHASE_AT_RESOLVE_IN_ROOT when AT_FDCWD or root dir fd is specified If we get AT_FDCWD or root dir fd, we always resolve symlinks relative to the host's root. Hence, the flag is meaningless. --- diff --git a/src/basic/chase.c b/src/basic/chase.c index 6c02aeab8ba..7b7664096f7 100644 --- a/src/basic/chase.c +++ b/src/basic/chase.c @@ -164,6 +164,20 @@ int chaseat( * the mount point is emitted. CHASE_WARN cannot be used in PID 1. */ + if (FLAGS_SET(flags, CHASE_AT_RESOLVE_IN_ROOT)) { + /* If we get AT_FDCWD or dir_fd points to "/", then we always resolve symlinks relative to + * the host's root. Hence, CHASE_AT_RESOLVE_IN_ROOT is meaningless. */ + + if (dir_fd >= 0) + r = dir_fd_is_root(dir_fd); + else + r = true; + if (r < 0) + return r; + if (r > 0) + flags &= ~CHASE_AT_RESOLVE_IN_ROOT; + } + if (!(flags & (CHASE_AT_RESOLVE_IN_ROOT|CHASE_NONEXISTENT|CHASE_NO_AUTOFS|CHASE_SAFE|CHASE_STEP| CHASE_PROHIBIT_SYMLINKS|CHASE_MKDIR_0755)) &&