grep: support NUL chars in search strings for -F
Search patterns in a file specified with -f can contain NUL characters. The current code ignores all characters on a line after a NUL. Pass the actual length of the line all the way from the pattern file to fixmatch() and use it for case-sensitive fixed string matching. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
f96e56733a
commit
ed40a0951c
@ -724,11 +724,15 @@ static int file_callback(const struct option *opt, const char *arg, int unset)
|
||||
if (!patterns)
|
||||
die_errno("cannot open '%s'", arg);
|
||||
while (strbuf_getline(&sb, patterns, '\n') == 0) {
|
||||
char *s;
|
||||
size_t len;
|
||||
|
||||
/* ignore empty line like grep does */
|
||||
if (sb.len == 0)
|
||||
continue;
|
||||
append_grep_pattern(grep_opt, strbuf_detach(&sb, NULL), arg,
|
||||
++lno, GREP_PATTERN);
|
||||
|
||||
s = strbuf_detach(&sb, &len);
|
||||
append_grep_pat(grep_opt, s, len, arg, ++lno, GREP_PATTERN);
|
||||
}
|
||||
fclose(patterns);
|
||||
strbuf_release(&sb);
|
||||
|
Reference in New Issue
Block a user