aboutsummaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-04-27 11:10:24 -0700
committerJunio C Hamano <gitster@pobox.com>2009-04-27 17:28:18 -0700
commitc922b01f54c4bebe84daeacf014cfbc8dc68479b (patch)
tree073eb94c6c06fa06013197a01ce703bda59b7923 /grep.c
parentd649048e68f2f5d59f6f961839c9e9772743a505 (diff)
downloadgit-c922b01f54c4bebe84daeacf014cfbc8dc68479b.tar.gz
git-c922b01f54c4bebe84daeacf014cfbc8dc68479b.tar.xz
grep: fix segfault when "git grep '('" is given
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/grep.c b/grep.c
index 13c18ff65..a4edacad8 100644
--- a/grep.c
+++ b/grep.c
@@ -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);