Skip to content

Commit b79376c

Browse files
committed
Merge branch 'maint'
* maint: 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 47afed5 + 2254da0 commit b79376c

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

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

grep.c

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

7474
p = *list;
75+
if (!p)
76+
return NULL;
7577
switch (p->token) {
7678
case GREP_PATTERN: /* atom */
7779
case GREP_PATTERN_HEAD:
@@ -84,8 +86,6 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
8486
case GREP_OPEN_PAREN:
8587
*list = p->next;
8688
x = compile_pattern_or(list);
87-
if (!x)
88-
return NULL;
8989
if (!*list || (*list)->token != GREP_CLOSE_PAREN)
9090
die("unmatched parenthesis");
9191
*list = (*list)->next;
@@ -101,6 +101,8 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list)
101101
struct grep_expr *x;
102102

103103
p = *list;
104+
if (!p)
105+
return NULL;
104106
switch (p->token) {
105107
case GREP_NOT:
106108
if (!p->next)
@@ -372,6 +374,8 @@ static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,
372374
int h = 0;
373375
regmatch_t match;
374376

377+
if (!x)
378+
die("Not a valid grep expression");
375379
switch (x->node) {
376380
case GREP_NODE_ATOM:
377381
h = match_one_pattern(x->u.atom, bol, eol, ctx, &match, 0);

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)