prefix_filename(): safely handle the case where pfx_len=0
Current prefix_filename() is proofed against the case where the prefix 'pfx' is NULL or a 0-length string, _except on Windows_. Change the behaviour to work the same on both platforms, and only check pfx_len so that callers passing a NULL prefix with a nonzero pfx_len segfault early on both. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Rast committed
Oct 17, 2010 at 21:23 UTC
9e5f5d4cfea5bb7706f1f8bb07795d52d37a59fe
1 file changed
+2
-2
setup.c
+2
-2
@@ -46,7 +46,7 @@ const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
46
{
47
static char path[PATH_MAX];
48
#ifndef WIN32
49
- if (!pfx || !*pfx || is_absolute_path(arg))
49
+ if (!pfx_len || is_absolute_path(arg))
50
return arg;
51
memcpy(path, pfx, pfx_len);
52
strcpy(path + pfx_len, arg);
@@ -55,7 +55,7 @@ const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
55
/* don't add prefix to absolute paths, but still replace '\' by '/' */
56
if (is_absolute_path(arg))
57
pfx_len = 0;
58
- else
58
+ else if (pfx_len)
59
memcpy(path, pfx, pfx_len);
60
strcpy(path + pfx_len, arg);
61
for (p = path + pfx_len; *p; p++)