Merge branch 'rs/grep-parser-fix'

"git grep --and -e foo" ought to have been diagnosed as an error
but instead segfaulted, which has been corrected.

* rs/grep-parser-fix:
  grep: report missing left operand of --and
This commit is contained in:
Junio C Hamano 2021-07-13 16:52:53 -07:00
Родитель 21ef7ee4d6 fe7fe62d8d
Коммит 1157618a2a
2 изменённых файлов: 11 добавлений и 0 удалений

2
grep.c
Просмотреть файл

@ -657,6 +657,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;

Просмотреть файл

@ -11,6 +11,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
test_invalid_grep_expression() {
params="$@" &&
test_expect_success "invalid expression: grep $params" '
test_must_fail git grep $params -- nonexisting
'
}
cat >hello.c <<EOF
#include <assert.h>
#include <stdio.h>
@ -89,6 +96,8 @@ test_expect_success 'grep should not segfault with a bad input' '
test_must_fail git grep "("
'
test_invalid_grep_expression --and -e A
for H in HEAD ''
do
case "$H" in