From: Mike Yuan Date: Wed, 8 Nov 2023 17:43:08 +0000 (+0800) Subject: basic/fileio: drop O_CREAT before passing flags to fd_reopen X-Git-Tag: v255-rc2~69^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F29939%2Fhead;p=thirdparty%2Fsystemd.git basic/fileio: drop O_CREAT before passing flags to fd_reopen Follow-up for 78c21009bfcf0758f9c85dc70ac896c8aab6b535 Fixes #29938 --- diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 6129461e660..a050b61db45 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -1064,7 +1064,9 @@ int fdopen_independent(int fd, const char *mode, FILE **ret) { if (mode_flags < 0) return mode_flags; - copy_fd = fd_reopen(fd, mode_flags); + /* Flags returned by fopen_mode_to_flags might contain O_CREAT, but it doesn't make sense for fd_reopen + * since we're working on an existing fd anyway. Let's drop it here to avoid triggering assertion. */ + copy_fd = fd_reopen(fd, mode_flags & ~O_CREAT); if (copy_fd < 0) return copy_fd;