Skip to content

Commit

Permalink
setup.c: stop prefix_pathspec() from looping past the end of string
Browse files Browse the repository at this point in the history
The code assumes that the string ends at either `)` or `,`, and does
not handle the case where strcspn() returns length due to end of
string.  So specifying ":(top" as pathspec will cause the loop to go
past the end of string.

Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Andrew Wong authored and Junio C Hamano committed Mar 14, 2013
1 parent 7e20105 commit 772e47c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,11 @@ static const char *prefix_pathspec(const char *prefix, int prefixlen, const char
*copyfrom && *copyfrom != ')';
copyfrom = nextat) {
size_t len = strcspn(copyfrom, ",)");
if (copyfrom[len] == ')')
nextat = copyfrom + len;
else
if (copyfrom[len] == ',')
nextat = copyfrom + len + 1;
else
/* handle ')' and '\0' */
nextat = copyfrom + len;
if (!len)
continue;
for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++)
Expand Down

0 comments on commit 772e47c

Please sign in to comment.