From: Jim Meyering Date: Mon, 18 Jan 2010 21:55:07 +0000 (+0100) Subject: grep: NUL terminate input from a file X-Git-Tag: v1.6.5.8~4^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=34f3999206e8ea41b9e4cf48e30ab1149e01d8a5;p=git.git grep: NUL terminate input from a file Internally "git grep" runs regexec(3) that expects its input string to be NUL terminated. When searching inside blob data, read_sha1_file() automatically gives such a buffer, but builtin-grep.c forgot to put the NUL at the end, even though it allocated enough space for it. Signed-off-by: Jim Meyering Signed-off-by: Junio C Hamano --- diff --git a/builtin-grep.c b/builtin-grep.c index d79a6260a..63dc31c45 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -207,6 +207,7 @@ static int grep_file(struct grep_opt *opt, const char *filename) return 0; } close(i); + data[sz] = 0; if (opt->relative && opt->prefix_length) filename = quote_path_relative(filename, -1, &buf, opt->prefix); i = grep_buffer(opt, filename, data, sz);