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

[PATCH v2 2/2] banned.h: mark ctime_r() and asctime_r() as banned.

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 1, 2020, 21:11 UTC
Message-ID
<20201201211138.33850-2-gitster@pobox.com>
In-Reply-To
<20201201211138.33850-1-gitster@pobox.com>
From: Jeff King <peff@peff.net>

The ctime_r() and asctime_r() functions are reentrant, but have no check that the buffer we pass in is long enough (the manpage says it "should have room for at least 26 bytes"). Since this is such an easy-to-get-wrong interface, and since we have the much safer stftime() as well as its more conveinent strbuf_addftime() wrapper, let's ban both of those.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 banned.h | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/banned.h b/banned.h
index ed11300bb2..7ab4f2e492 100644
--- a/banned.h
+++ b/banned.h
@@ -35,7 +35,11 @@
 #define localtime(t) BANNED(localtime)
 #undef ctime
 #define ctime(t) BANNED(ctime)
+#undef ctime_r
+#define ctime_r(t, buf) BANNED(ctime_r)
 #undef asctime
 #define asctime(t) BANNED(asctime)
+#undef asctime_r
+#define asctime_r(t, buf) BANNED(asctime_r)
 
 #endif /* BANNED_H */
-- 
2.29.2-561-g49e167ef76
Previous: Junio C HamanoNext: Eric Sunshine
Message 8 of 14 in “builtin/bugreport.c: use thread-safe localtime_r()”
  1. builtin/bugreport.c: use thread-safe localtime_r()Taylor Blau, Nov 30, 2020
  2. builtin/bugreport.c: use thread-safe localtime_r()Taylor Blau, Dec 1, 2020
  3. Jeff KingDec 1, 2020
  4. Eric SunshineDec 1, 2020
  5. Junio C HamanoDec 1, 2020
  6. Taylor BlauDec 1, 2020
  7. 1/2 banned.h: mark non-reentrant gmtime, etc as bannedJunio C Hamano, Dec 1, 2020
  8. 2/2 banned.h: mark ctime_r() and asctime_r() as banned.Junio C Hamano, Dec 1, 2020
  9. Eric SunshineDec 1, 2020
  10. Junio C HamanoDec 1, 2020
  11. Taylor BlauDec 1, 2020
  12. SZEDER GáborDec 6, 2020
  13. Jeff KingDec 2, 2020
  14. Eric SunshineDec 1, 2020

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.