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
diff --git a/Documentation/technical/api-builtin.txt b/Documentation/technical/api-builtin.txt
index 7ede1e6..5cb2b05 100644
--- a/Documentation/technical/api-builtin.txt
+++ b/Documentation/technical/api-builtin.txt
@@ -37,7 +37,7 @@
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 6d2160d..c339380 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -765,7 +765,7 @@
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 062b2b6..b0d992a 100644
--- a/grep.c
+++ b/grep.c
@@ -70,6 +70,8 @@
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 @@
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 @@
struct grep_expr *x;
p = *list;
+ if (!p)
+ return NULL;
switch (p->token) {
case GREP_NOT:
if (!p->next)
@@ -386,6 +388,8 @@
{
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 c493854..b815937 100755
--- a/t/t7002-grep.sh
+++ b/t/t7002-grep.sh
@@ -26,6 +26,10 @@
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