Thread (5 messages) flat view 5 messages, 2 authors, 2016-06-15

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

From: Michael Haggerty <hidden>
Date: 2016-06-15 22:52:07

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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help