From d204af1e414662d5947241d853b4355db116e8f6 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Wed, 5 Apr 2017 20:11:05 +0000 Subject: [PATCH] bsdgrep: Handle special case of single-byte NUL pattern PR: 202022 Submitted by: Kyle Evans MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D10102 --- usr.bin/grep/grep.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index 4961c5b009a2..c9a8d71a3c97 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -314,8 +314,12 @@ read_patterns(const char *fn) } len = 0; line = NULL; - while ((rlen = getline(&line, &len, f)) != -1) + while ((rlen = getline(&line, &len, f)) != -1) { + if (line[0] == '\0') + continue; add_pattern(line, line[0] == '\n' ? 0 : (size_t)rlen); + } + free(line); if (ferror(f)) err(2, "%s", fn);