]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fileio: mask off O_NOFOLLOW in xfopenat_regular() for fd_reopen()
authorMike Yuan <me@yhndnzj.com>
Mon, 3 Nov 2025 20:59:34 +0000 (21:59 +0100)
committerMike Yuan <me@yhndnzj.com>
Mon, 3 Nov 2025 21:32:25 +0000 (22:32 +0100)
in a similar fashion as xopenat_full()

src/basic/fileio.c

index a493384c52de42bd7575f38e5ecc942262682bc8..a3860abefbeccc1b3e6c54f4a45d1f7786ce2b38 100644 (file)
@@ -1011,7 +1011,7 @@ static int xfopenat_regular(int dir_fd, const char *path, const char *mode, int
         assert(mode);
         assert(ret);
 
-        if (dir_fd == AT_FDCWD && open_flags == 0 && path)
+        if (dir_fd == AT_FDCWD && path && open_flags == 0)
                 f = fopen(path, mode);
         else {
                 _cleanup_close_ int fd = -EBADF;
@@ -1029,7 +1029,7 @@ static int xfopenat_regular(int dir_fd, const char *path, const char *mode, int
                         if (dir_fd == AT_FDCWD)
                                 return -EBADF;
 
-                        fd = fd_reopen(dir_fd, mode_flags | open_flags);
+                        fd = fd_reopen(dir_fd, (mode_flags | open_flags) & ~O_NOFOLLOW);
                         if (fd < 0)
                                 return fd;
                 }