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

[RFC][PATCH] mingw: avoid mktemp() in mkstemp() implementation

From
René Scharfe <l.s.r@web.de>
Date
Jul 15, 2022, 03:58 UTC
Message-ID
<7265e37f-fd29-3579-b840-19a1df52a59f@web.de>

The implementation of mkstemp() for MinGW uses mktemp() and open() without the flag O_EXCL, which is racy. It's not a security problem for now because all of its callers only create files within the repository (incl. worktrees). Replace it with a call to our more secure internal function, git_mkstemp_mode(), to prevent possible future issues.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 compat/mingw.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/compat/mingw.c b/compat/mingw.c
index 2607de93af..b5502997e2 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1059,10 +1059,7 @@ char *mingw_mktemp(char *template)

 int mkstemp(char *template)
 {
-	char *filename = mktemp(template);
-	if (!filename)
-		return -1;
-	return open(filename, O_RDWR | O_CREAT, 0600);
+	return git_mkstemp_mode(template, 0600);
 }

 int gettimeofday(struct timeval *tv, void *tz)
--
2.37.0
Next: Johannes Sixt
Message 1 of 5 in “mingw: avoid mktemp() in mkstemp() implementation”
  1. René ScharfeJul 15, 2022
  2. Johannes SixtJul 15, 2022
  3. Junio C HamanoJul 15, 2022
  4. René ScharfeJul 16, 2022
  5. Johannes SchindelinJul 15, 2022

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.