Skip to content

Commit fa0a6a4

Browse files
committed
Merge branch 'lf/setup-prefix-pathspec' into maint
"git cmd -- ':(top'" was not diagnosed as an invalid syntax, and instead the parser kept reading beyond the end of the string. * lf/setup-prefix-pathspec: setup.c: check that the pathspec magic ends with ")" setup.c: stop prefix_pathspec() from looping past the end of string
2 parents 92e0d91 + f612a67 commit fa0a6a4

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

setup.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,11 @@ static const char *prefix_pathspec(const char *prefix, int prefixlen, const char
207207
*copyfrom && *copyfrom != ')';
208208
copyfrom = nextat) {
209209
size_t len = strcspn(copyfrom, ",)");
210-
if (copyfrom[len] == ')')
211-
nextat = copyfrom + len;
212-
else
210+
if (copyfrom[len] == ',')
213211
nextat = copyfrom + len + 1;
212+
else
213+
/* handle ')' and '\0' */
214+
nextat = copyfrom + len;
214215
if (!len)
215216
continue;
216217
for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++)
@@ -223,8 +224,9 @@ static const char *prefix_pathspec(const char *prefix, int prefixlen, const char
223224
die("Invalid pathspec magic '%.*s' in '%s'",
224225
(int) len, copyfrom, elt);
225226
}
226-
if (*copyfrom == ')')
227-
copyfrom++;
227+
if (*copyfrom != ')')
228+
die("Missing ')' at the end of pathspec magic in '%s'", elt);
229+
copyfrom++;
228230
} else {
229231
/* shorthand */
230232
for (copyfrom = elt + 1;

0 commit comments

Comments
 (0)