summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-09-24 17:07:47 -0400
committerJunio C Hamano <gitster@pobox.com>2015-10-05 11:08:05 -0700
commit4635768809885bb1c063bc9f9eee38e413f85f0d (patch)
tree8ae8f250cb48f657b538ed54d646b8b7eb07a974
parente9ba678175da28607d57043e1363c6252880dd7f (diff)
downloadgit-4635768809885bb1c063bc9f9eee38e413f85f0d.tar.gz
remove_leading_path: use a strbuf for internal storage
This function strcpy's directly into a PATH_MAX-sized buffer. There's only one caller, which feeds the git_dir into it, so it's not easy to trigger in practice (even if you fed a large $GIT_DIR through the environment or .git file, it would have to actually exist and be accessible on the filesystem to get to this point). We can fix it by moving to a strbuf. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--path.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/path.c b/path.c
index 60e0390906..c597473e62 100644
--- a/path.c
+++ b/path.c
@@ -632,7 +632,7 @@ const char *relative_path(const char *in, const char *prefix,
*/
const char *remove_leading_path(const char *in, const char *prefix)
{
- static char buf[PATH_MAX + 1];
+ static struct strbuf buf = STRBUF_INIT;
int i = 0, j = 0;
if (!prefix || !prefix[0])
@@ -661,11 +661,13 @@ const char *remove_leading_path(const char *in, const char *prefix)
return in;
while (is_dir_sep(in[j]))
j++;
+
+ strbuf_reset(&buf);
if (!in[j])
- strcpy(buf, ".");
+ strbuf_addstr(&buf, ".");
else
- strcpy(buf, in + j);
- return buf;
+ strbuf_addstr(&buf, in + j);
+ return buf.buf;
}
/*