Skip to content

Commit 34f3999

Browse files
meyeringgitster
authored andcommitted
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 <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 527b9d7 commit 34f3999

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

builtin-grep.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ static int grep_file(struct grep_opt *opt, const char *filename)
207207
return 0;
208208
}
209209
close(i);
210+
data[sz] = 0;
210211
if (opt->relative && opt->prefix_length)
211212
filename = quote_path_relative(filename, -1, &buf, opt->prefix);
212213
i = grep_buffer(opt, filename, data, sz);

0 commit comments

Comments
 (0)