Skip to content
/ git Public
forked from git/git

Commit

Permalink
Merge branch 'lf/setup-prefix-pathspec'
Browse files Browse the repository at this point in the history
"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
  • Loading branch information
gitster committed Mar 25, 2013
2 parents 33c1506 + f612a67 commit 51ebd0f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions setup.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -207,10 +207,11 @@ static const char *prefix_pathspec(const char *prefix, int prefixlen, const char
*copyfrom && *copyfrom != ')'; *copyfrom && *copyfrom != ')';
copyfrom = nextat) { copyfrom = nextat) {
size_t len = strcspn(copyfrom, ",)"); size_t len = strcspn(copyfrom, ",)");
if (copyfrom[len] == ')') if (copyfrom[len] == ',')
nextat = copyfrom + len;
else
nextat = copyfrom + len + 1; nextat = copyfrom + len + 1;
else
/* handle ')' and '\0' */
nextat = copyfrom + len;
if (!len) if (!len)
continue; continue;
for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++) for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++)
Expand All @@ -223,8 +224,9 @@ static const char *prefix_pathspec(const char *prefix, int prefixlen, const char
die("Invalid pathspec magic '%.*s' in '%s'", die("Invalid pathspec magic '%.*s' in '%s'",
(int) len, copyfrom, elt); (int) len, copyfrom, elt);
} }
if (*copyfrom == ')') if (*copyfrom != ')')
copyfrom++; die("Missing ')' at the end of pathspec magic in '%s'", elt);
copyfrom++;
} else { } else {
/* shorthand */ /* shorthand */
for (copyfrom = elt + 1; for (copyfrom = elt + 1;
Expand Down

0 comments on commit 51ebd0f

Please sign in to comment.