Skip to content

Commit 9e5f5d4

Browse files
trastgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 352953a commit 9e5f5d4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
4646
{
4747
static char path[PATH_MAX];
4848
#ifndef WIN32
49-
if (!pfx || !*pfx || is_absolute_path(arg))
49+
if (!pfx_len || is_absolute_path(arg))
5050
return arg;
5151
memcpy(path, pfx, pfx_len);
5252
strcpy(path + pfx_len, arg);
@@ -55,7 +55,7 @@ const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
5555
/* don't add prefix to absolute paths, but still replace '\' by '/' */
5656
if (is_absolute_path(arg))
5757
pfx_len = 0;
58-
else
58+
else if (pfx_len)
5959
memcpy(path, pfx, pfx_len);
6060
strcpy(path + pfx_len, arg);
6161
for (p = path + pfx_len; *p; p++)

0 commit comments

Comments
 (0)