summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Documentation/technical/api-builtin.txt2
-rw-r--r--builtin-merge.c2
-rw-r--r--grep.c8
-rwxr-xr-xt/t7002-grep.sh4
4 files changed, 12 insertions, 4 deletions
diff --git a/Documentation/technical/api-builtin.txt b/Documentation/technical/api-builtin.txt
index 7ede1e64e5..5cb2b0590a 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 6a51823a55..0b58e5eda1 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -764,7 +764,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 f3a27d7d6e..04c777a20c 100644
--- a/grep.c
+++ b/grep.c
@@ -72,6 +72,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:
@@ -84,8 +86,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;
@@ -101,6 +101,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)
@@ -372,6 +374,8 @@ static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,
int h = 0;
regmatch_t match;
+ if (!x)
+ die("Not a valid grep expression");
switch (x->node) {
case GREP_NODE_ATOM:
h = match_one_pattern(x->u.atom, bol, eol, ctx, &match, 0);
diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh
index c4938544d4..b81593780a 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