Commit c922b01f authored by Linus Torvalds's avatar Linus Torvalds Committed by Junio C Hamano

grep: fix segfault when "git grep '('" is given

Signed-off-by: default avatarLinus Torvalds <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent d649048e
......@@ -54,6 +54,8 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
struct grep_expr *x;
p = *list;
if (!p)
return NULL;
switch (p->token) {
case GREP_PATTERN: /* atom */
case GREP_PATTERN_HEAD:
......@@ -66,8 +68,6 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
case GREP_OPEN_PAREN:
*list = p->next;
x = compile_pattern_or(list);
if (!x)
return NULL;
if (!*list || (*list)->token != GREP_CLOSE_PAREN)
die("unmatched parenthesis");
*list = (*list)->next;
......@@ -83,6 +83,8 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list)
struct grep_expr *x;
p = *list;
if (!p)
return NULL;
switch (p->token) {
case GREP_NOT:
if (!p->next)
......@@ -361,6 +363,8 @@ static int match_expr_eval(struct grep_opt *o,
{
int h = 0;
if (!x)
die("Not a valid grep expression");
switch (x->node) {
case GREP_NODE_ATOM:
h = match_one_pattern(o, x->u.atom, bol, eol, ctx);
......
......@@ -26,6 +26,10 @@ test_expect_success setup '
git commit -m initial
'
test_expect_success 'grep should not segfault with a bad input' '
test_must_fail git grep "("
'
for H in HEAD ''
do
case "$H" in
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment