Skip to content

Commit

Permalink
grep: NUL terminate input from a file
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
meyering authored and gitster committed Jan 19, 2010
1 parent 527b9d7 commit 34f3999
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions builtin-grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 34f3999

Please sign in to comment.