summaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2021-06-30 16:12:43 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-06-30 21:19:03 (GMT)
commitfe7fe62d8da0949d9b2bca34467b349bd294e91b (patch)
treefbac7dfc8393c1aae8245f860fc1ab102215530b /grep.c
parent8b1a5f33d3ed427b0a6eaee595537805db6bc38c (diff)
downloadgit-fe7fe62d8da0949d9b2bca34467b349bd294e91b.zip
git-fe7fe62d8da0949d9b2bca34467b349bd294e91b.tar.gz
git-fe7fe62d8da0949d9b2bca34467b349bd294e91b.tar.bz2
grep: report missing left operand of --and
Git grep allows combining two patterns with --and. It checks and reports if the second pattern is missing when compiling the expression. A missing first pattern, however, is only reported later at match time. Thus no error is returned if no matching is done, e.g. because no file matches the also given pathspec. When that happens we get an expression tree with an GREP_NODE_AND node and a NULL pointer to the missing left child. free_pattern_expr() tries to dereference it during the cleanup at the end, which results in a segmentation fault. Fix this by verifying the presence of the left operand at expression compilation time. Reported-by: Matthew Hughes <matthewhughes934@gmail.com> Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/grep.c b/grep.c
index 4db1510..71e4440 100644
--- a/grep.c
+++ b/grep.c
@@ -774,6 +774,8 @@ static struct grep_expr *compile_pattern_and(struct grep_pat **list)
x = compile_pattern_not(list);
p = *list;
if (p && p->token == GREP_AND) {
+ if (!x)
+ die("--and not preceded by pattern expression");
if (!p->next)
die("--and not followed by pattern expression");
*list = p->next;