From: Michael Haggerty <mhagger@alum.mit.edu>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Petr Baudis <pasky@suse.cz>,
Michael Haggerty <mhagger@alum.mit.edu>
Subject: [RFC 1/2] Make the number of pathname buffers a compile-time constant
Date: Tue, 27 Sep 2011 06:28:06 +0200 [thread overview]
Message-ID: <1317097687-11098-2-git-send-email-mhagger@alum.mit.edu> (raw)
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
next prev parent reply other threads:[~2011-09-27 4:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-27 4:28 [RFC 0/2] Debugging tools for get_pathname() Michael Haggerty
2011-09-27 4:28 ` Michael Haggerty [this message]
2011-09-27 4:28 ` [RFC 2/2] Make misuse of get_pathname() buffers detectable by valgrind Michael Haggerty
2011-11-16 13:57 ` Nguyen Thai Ngoc Duy
2011-11-16 14:18 ` Nguyen Thai Ngoc Duy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1317097687-11098-2-git-send-email-mhagger@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pasky@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).