Skip to content

Commit 3e73cb2

Browse files
committed
Merge branch 'maint-1.6.0' into maint-1.6.1
* maint-1.6.0: grep: fix segfault when "git grep '('" is given Documentation: fix a grammatical error in api-builtin.txt builtin-merge: fix a typo in an error message
2 parents cc13719 + c922b01 commit 3e73cb2

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

Documentation/technical/api-builtin.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ where options is the bitwise-or of:
3737

3838
Make sure there is a work tree, i.e. the command cannot act
3939
on bare repositories.
40-
This makes only sense when `RUN_SETUP` is also set.
40+
This only makes sense when `RUN_SETUP` is also set.
4141

4242
. Add `builtin-foo.o` to `BUILTIN_OBJS` in `Makefile`.
4343

builtin-merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ static int suggest_conflicts(void)
785785

786786
fp = fopen(git_path("MERGE_MSG"), "a");
787787
if (!fp)
788-
die("Could open %s for writing", git_path("MERGE_MSG"));
788+
die("Could not open %s for writing", git_path("MERGE_MSG"));
789789
fprintf(fp, "\nConflicts:\n");
790790
for (pos = 0; pos < active_nr; pos++) {
791791
struct cache_entry *ce = active_cache[pos];

grep.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
5454
struct grep_expr *x;
5555

5656
p = *list;
57+
if (!p)
58+
return NULL;
5759
switch (p->token) {
5860
case GREP_PATTERN: /* atom */
5961
case GREP_PATTERN_HEAD:
@@ -66,8 +68,6 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
6668
case GREP_OPEN_PAREN:
6769
*list = p->next;
6870
x = compile_pattern_or(list);
69-
if (!x)
70-
return NULL;
7171
if (!*list || (*list)->token != GREP_CLOSE_PAREN)
7272
die("unmatched parenthesis");
7373
*list = (*list)->next;
@@ -83,6 +83,8 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list)
8383
struct grep_expr *x;
8484

8585
p = *list;
86+
if (!p)
87+
return NULL;
8688
switch (p->token) {
8789
case GREP_NOT:
8890
if (!p->next)
@@ -368,6 +370,8 @@ static int match_expr_eval(struct grep_opt *o,
368370
{
369371
int h = 0;
370372

373+
if (!x)
374+
die("Not a valid grep expression");
371375
switch (x->node) {
372376
case GREP_NODE_ATOM:
373377
h = match_one_pattern(o, x->u.atom, bol, eol, ctx);

t/t7002-grep.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ test_expect_success setup '
2626
git commit -m initial
2727
'
2828

29+
test_expect_success 'grep should not segfault with a bad input' '
30+
test_must_fail git grep "("
31+
'
32+
2933
for H in HEAD ''
3034
do
3135
case "$H" in

0 commit comments

Comments
 (0)