Skip to content

Commit 62525ef

Browse files
dmpotspearce
authored andcommitted
make prefix_path() never return NULL
There are 9 places where prefix_path is called, and only in one of them the returned pointer was checked to be non-zero and only to call exit(128) as it is usually done by die(). In other 8 places, the returned value was not checked and it caused SIGSEGV when a path outside of the working tree was used. For instance, running git update-index --add /some/path/outside caused SIGSEGV. This patch changes prefix_path() to die if the path is outside of the repository, so it never returns NULL. Signed-off-by: Dmitry Potapov <dpotapov@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
1 parent 71b989e commit 62525ef

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

setup.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ const char *prefix_path(const char *prefix, int len, const char *path)
110110
if (strncmp(sanitized, work_tree, len) ||
111111
(sanitized[len] != '\0' && sanitized[len] != '/')) {
112112
error_out:
113-
error("'%s' is outside repository", orig);
114-
free(sanitized);
115-
return NULL;
113+
die("'%s' is outside repository", orig);
116114
}
117115
if (sanitized[len] == '/')
118116
len++;
@@ -216,10 +214,7 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
216214
prefixlen = prefix ? strlen(prefix) : 0;
217215
while (*src) {
218216
const char *p = prefix_path(prefix, prefixlen, *src);
219-
if (p)
220-
*(dst++) = p;
221-
else
222-
exit(128); /* error message already given */
217+
*(dst++) = p;
223218
src++;
224219
}
225220
*dst = NULL;

0 commit comments

Comments
 (0)