git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] open: check fd_flags value before calling fcntl
@ 2025-12-18  3:14 AZero13 via GitGitGadget
  2025-12-18  3:45 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: AZero13 via GitGitGadget @ 2025-12-18  3:14 UTC (permalink / raw)
  To: git; +Cc: AZero13, AZero13

From: AZero13 <gfunni234@gmail.com>

Otherwise, fcntl can be called with invalid fd_flags.

Signed-off-by: Greg Funni <gfunni234@gmail.com>
---
    open: check fd_flags value before calling fcntl
    
    Otherwise, fcntl can be called with invalid fd_flags.
    
    Signed-off-by:Greg Funni gfunni234@gmail.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2131%2FAZero13%2Ffixopen-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2131/AZero13/fixopen-v1
Pull-Request: https://github.com/git/git/pull/2131

 compat/open.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/compat/open.c b/compat/open.c
index 37ae2b1aeb..b313bcd364 100644
--- a/compat/open.c
+++ b/compat/open.c
@@ -44,8 +44,8 @@ int git_open_cloexec(const char *name, int flags)
 
 		if (!o_cloexec && 0 <= fd && fd_cloexec) {
 			/* Opened w/o O_CLOEXEC?  try with fcntl(2) to add it */
-			int flags = fcntl(fd, F_GETFD);
-			if (fcntl(fd, F_SETFD, flags | fd_cloexec))
+			int fd_flags = fcntl(fd, F_GETFD);
+			if (fd_flags < 0 || fcntl(fd, F_SETFD, fd_flags | fd_cloexec))
 				fd_cloexec = 0;
 		}
 	}

base-commit: c4a0c8845e2426375ad257b6c221a3a7d92ecfda
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-12-18  3:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-18  3:14 [PATCH] open: check fd_flags value before calling fcntl AZero13 via GitGitGadget
2025-12-18  3:45 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).