git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] open: check fd_flags value before calling fcntl

From
AGAZero13 via GitGitGadget <gitgitgadget@gmail.com>
Date
Dec 18, 2025, 03:14 UTC
Message-ID
<pull.2131.git.git.1766027643744.gitgitgadget@gmail.com>
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
Next: Junio C Hamano
Message 1 of 2 in “open: check fd_flags value before calling fcntl”
  1. open: check fd_flags value before calling fcntlAZero13 via GitGitGadget, Dec 18, 2025
  2. Junio C HamanoDec 18, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.