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

[RFC 1/2] Make the number of pathname buffers a compile-time constant

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Sep 27, 2011, 04:28 UTC
Message-ID
<1317097687-11098-2-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1317097687-11098-1-git-send-email-mhagger@alum.mit.edu>

Changing the number of available temporary buffers for get_pathname() can help diagnose abuse of such buffers. If a bug goes away when PATHNAME_BUFFER_COUNT is increased, then it might be due to a buffer being used after it has been recycled. Similarly, if a bug appears when PATHNAME_BUFFER_COUNT is decreased, then there might be a latent problem that could emerge after unrelated code changes.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 path.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
diff --git path.c path.c
index 6f3f5d5..6c4714d 100644
--- path.c
+++ path.c
@@ -13,13 +13,16 @@
 #include "cache.h"
 #include "strbuf.h"
 
+/* This must be a power of 2: */
+#define PATHNAME_BUFFER_COUNT (1 << 2)
+
 static char bad_path[] = "/bad-path/";
 
 static char *get_pathname(void)
 {
-	static char pathname_array[4][PATH_MAX];
+	static char pathname_array[PATHNAME_BUFFER_COUNT][PATH_MAX];
 	static int index;
-	return pathname_array[3 & ++index];
+	return pathname_array[(PATHNAME_BUFFER_COUNT - 1) & ++index];
 }
 
 static char *cleanup_path(char *path)
-- 
1.7.7.rc2
Previous: Michael HaggertyNext: Michael Haggerty
Message 2 of 5 in “[RFC 0/2] Debugging tools for get_pathname()”
  1. Michael HaggertySep 27, 2011
  2. 1/2 Make the number of pathname buffers a compile-time constantMichael Haggerty, Sep 27, 2011
  3. 2/2 Make misuse of get_pathname() buffers detectable by valgrindMichael Haggerty, Sep 27, 2011
  4. Nguyen Thai Ngoc DuyNov 16, 2011
  5. Nguyen Thai Ngoc DuyNov 16, 2011

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.