Skip to content

Commit 2254da0

Browse files
committed
Merge branch 'maint-1.6.1' into maint
* maint-1.6.1: 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 f06b9f1 + 3e73cb2 commit 2254da0

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
@@ -765,7 +765,7 @@ static int suggest_conflicts(void)
765765

766766
fp = fopen(git_path("MERGE_MSG"), "a");
767767
if (!fp)
768-
die("Could open %s for writing", git_path("MERGE_MSG"));
768+
die("Could not open %s for writing", git_path("MERGE_MSG"));
769769
fprintf(fp, "\nConflicts:\n");
770770
for (pos = 0; pos < active_nr; pos++) {
771771
struct cache_entry *ce = active_cache[pos];

grep.c

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

7272
p = *list;
73+
if (!p)
74+
return NULL;
7375
switch (p->token) {
7476
case GREP_PATTERN: /* atom */
7577
case GREP_PATTERN_HEAD:
@@ -82,8 +84,6 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
8284
case GREP_OPEN_PAREN:
8385
*list = p->next;
8486
x = compile_pattern_or(list);
85-
if (!x)
86-
return NULL;
8787
if (!*list || (*list)->token != GREP_CLOSE_PAREN)
8888
die("unmatched parenthesis");
8989
*list = (*list)->next;
@@ -99,6 +99,8 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list)
9999
struct grep_expr *x;
100100

101101
p = *list;
102+
if (!p)
103+
return NULL;
102104
switch (p->token) {
103105
case GREP_NOT:
104106
if (!p->next)
@@ -386,6 +388,8 @@ static int match_expr_eval(struct grep_opt *o,
386388
{
387389
int h = 0;
388390

391+
if (!x)
392+
die("Not a valid grep expression");
389393
switch (x->node) {
390394
case GREP_NODE_ATOM:
391395
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)