From: Linus Torvalds <torvalds@linux-foundation.org>
To: Dmitry Potapov <dpotapov@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: git grep '(' = segfault
Date: Mon, 27 Apr 2009 11:10:24 -0700 (PDT) [thread overview]
Message-ID: <alpine.LFD.2.00.0904271059060.22156@localhost.localdomain> (raw)
In-Reply-To: <37fcd2780904271046r7740ed42t3c9438e7aa93374@mail.gmail.com>
On Mon, 27 Apr 2009, Dmitry Potapov wrote:
>
> I have tried a few version of Git and got "Segmentation fault" when
> run:
>
> $ git grep '('
>
> I am not very familiar with grep code and don't have time to dig
> into it right now. So, maybe someone else can take a look at it.
Good job.
Something like this should fix it.
Linus
---
grep.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/grep.c b/grep.c
index f3a27d7..04c777a 100644
--- a/grep.c
+++ b/grep.c
@@ -72,6 +72,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:
@@ -84,8 +86,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;
@@ -101,6 +101,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)
@@ -372,6 +374,8 @@ static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,
int h = 0;
regmatch_t match;
+ if (!x)
+ die("Not a valid grep expression");
switch (x->node) {
case GREP_NODE_ATOM:
h = match_one_pattern(x->u.atom, bol, eol, ctx, &match, 0);
next prev parent reply other threads:[~2009-04-27 18:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-27 17:46 git grep '(' = segfault Dmitry Potapov
2009-04-27 18:10 ` Linus Torvalds [this message]
2009-04-27 18:42 ` Erik Faye-Lund
2009-04-27 18:50 ` Linus Torvalds
2009-04-27 18:53 ` Erik Faye-Lund
2009-04-27 18:54 ` Matthieu Moy
2009-04-27 19:02 ` Erik Faye-Lund
2009-04-27 23:18 ` Junio C Hamano
2009-04-27 18:15 ` Michał Kiedrowicz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LFD.2.00.0904271059060.22156@localhost.localdomain \
--to=torvalds@linux-foundation.org \
--cc=dpotapov@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).