diff --git a/Documentation/technical/api-builtin.txt b/Documentation/technical/api-builtin.txt index 7ede1e64e5d40ec8f742e900d7273d6f961605e2..5cb2b0590abb1fc4e4685097ba3cdd3d0683a95f 100644 --- a/Documentation/technical/api-builtin.txt +++ b/Documentation/technical/api-builtin.txt @@ -37,7 +37,7 @@ where options is the bitwise-or of: Make sure there is a work tree, i.e. the command cannot act on bare repositories. - This makes only sense when `RUN_SETUP` is also set. + This only makes sense when `RUN_SETUP` is also set. . Add `builtin-foo.o` to `BUILTIN_OBJS` in `Makefile`. diff --git a/builtin-merge.c b/builtin-merge.c index 6d2160d0a3db1705d1372029dfa24752d453c8ec..c339380cf3a94c5c157e7b3fae082ea2321320fc 100644 --- a/builtin-merge.c +++ b/builtin-merge.c @@ -765,7 +765,7 @@ static int suggest_conflicts(void) fp = fopen(git_path("MERGE_MSG"), "a"); if (!fp) - die("Could open %s for writing", git_path("MERGE_MSG")); + die("Could not open %s for writing", git_path("MERGE_MSG")); fprintf(fp, "\nConflicts:\n"); for (pos = 0; pos < active_nr; pos++) { struct cache_entry *ce = active_cache[pos]; diff --git a/grep.c b/grep.c index 062b2b6f28f6332518240d2a474a7739735e1ecf..b0d992a6e0a838d0fb4e71e3a8bebe8266ed1070 100644 --- a/grep.c +++ b/grep.c @@ -70,6 +70,8 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list) struct grep_expr *x; p = *list; + if (!p) + return NULL; switch (p->token) { case GREP_PATTERN: /* atom */ case GREP_PATTERN_HEAD: @@ -82,8 +84,6 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list) case GREP_OPEN_PAREN: *list = p->next; x = compile_pattern_or(list); - if (!x) - return NULL; if (!*list || (*list)->token != GREP_CLOSE_PAREN) die("unmatched parenthesis"); *list = (*list)->next; @@ -99,6 +99,8 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list) struct grep_expr *x; p = *list; + if (!p) + return NULL; switch (p->token) { case GREP_NOT: if (!p->next) @@ -386,6 +388,8 @@ static int match_expr_eval(struct grep_opt *o, { int h = 0; + if (!x) + die("Not a valid grep expression"); switch (x->node) { case GREP_NODE_ATOM: h = match_one_pattern(o, x->u.atom, bol, eol, ctx); diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index c4938544d4ca7c5e7e886a59144c9b10b7971748..b81593780a2a6adaf34bb10293b607e3a303cfcd 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -26,6 +26,10 @@ test_expect_success setup ' git commit -m initial ' +test_expect_success 'grep should not segfault with a bad input' ' + test_must_fail git grep "(" +' + for H in HEAD '' do case "$H" in