]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
chase: drop CHASE_AT_RESOLVE_IN_ROOT when AT_FDCWD or root dir fd is specified
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 30 Mar 2023 04:15:59 +0000 (13:15 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 30 Mar 2023 07:29:37 +0000 (16:29 +0900)
If we get AT_FDCWD or root dir fd, we always resolve symlinks relative to the host's root.
Hence, the flag is meaningless.

src/basic/chase.c

index 6c02aeab8ba2ebea7764d192351c5b30a9c80c2e..7b7664096f78abce9b5f969528b47e3b82871dc4 100644 (file)
@@ -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)) &&