Skip to content

Commit 772e47c

Browse files
andrewkwwgitster
authored andcommitted
setup.c: stop prefix_pathspec() from looping past the end of string
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7e20105 commit 772e47c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

setup.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,11 @@ static const char *prefix_pathspec(const char *prefix, int prefixlen, const char
199199
*copyfrom && *copyfrom != ')';
200200
copyfrom = nextat) {
201201
size_t len = strcspn(copyfrom, ",)");
202-
if (copyfrom[len] == ')')
203-
nextat = copyfrom + len;
204-
else
202+
if (copyfrom[len] == ',')
205203
nextat = copyfrom + len + 1;
204+
else
205+
/* handle ')' and '\0' */
206+
nextat = copyfrom + len;
206207
if (!len)
207208
continue;
208209
for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++)

0 commit comments

Comments
 (0)