diff options
author | Mike Yuan <me@yhndnzj.com> | 2023-11-08 18:43:08 +0100 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2023-11-08 20:38:14 +0100 |
commit | 6f9677bc7f6139c7ea805ae7c7064a7f67568bee (patch) | |
tree | 5373009359a8b9364eff594ca394e0e3aa9cee0f /src/basic/fileio.c | |
parent | fd-util: refuse O_CREAT in fd_reopen (diff) | |
download | systemd-6f9677bc7f6139c7ea805ae7c7064a7f67568bee.tar.xz systemd-6f9677bc7f6139c7ea805ae7c7064a7f67568bee.zip |
basic/fileio: drop O_CREAT before passing flags to fd_reopen
Follow-up for 78c21009bfcf0758f9c85dc70ac896c8aab6b535
Fixes #29938
Diffstat (limited to 'src/basic/fileio.c')
-rw-r--r-- | src/basic/fileio.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 6129461e66..a050b61db4 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; |