From: Matt Kraai Date: Fri, 16 Oct 2009 14:13:25 +0000 (-0700) Subject: grep: do not segfault when -f is used X-Git-Tag: v1.6.5.1~1^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=cfe370c6476392095bc3f18013d195b1cccd6184;p=git.git grep: do not segfault when -f is used "git grep" would segfault if its -f option was used because it would try to use an uninitialized strbuf, so initialize the strbuf. Thanks to Johannes Sixt for the help with the test cases. Signed-off-by: Matt Kraai Signed-off-by: Junio C Hamano --- diff --git a/builtin-grep.c b/builtin-grep.c index fd450bc16..e3b940b93 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -599,7 +599,7 @@ static int file_callback(const struct option *opt, const char *arg, int unset) struct grep_opt *grep_opt = opt->value; FILE *patterns; int lno = 0; - struct strbuf sb; + struct strbuf sb = STRBUF_INIT; patterns = fopen(arg, "r"); if (!patterns) diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index 6ca11d714..5f91d8229 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -164,6 +164,72 @@ test_expect_success 'grep -e A --and --not -e B' ' test_cmp expected actual ' +test_expect_success 'grep -f, non-existent file' ' + test_must_fail git grep -f patterns +' + +cat >expected <pattern <actual && + test_cmp expected actual +' + +cat >expected <patterns <actual && + test_cmp expected actual +' + +cat >expected <patterns <actual && + test_cmp expected actual +' + cat >expected <