bsdgrep(1): Fix errors with invalid expressions

Invalid expressions with an ultimate compiled pattern length of 0 (e.g.,
"grep -E {") were not taken into account and caused a segfault while trying
to fill in the good suffix table.

Submitted by:	Kyle Evans <kevans91 at ksu.edu>
Reviewed by:	me
Differential Revision:	https://reviews.freebsd.org/D10113
This commit is contained in:
Conrad Meyer 2017-04-04 17:05:37 +00:00
parent fd70242dbc
commit f48d142551
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=316495

View File

@ -337,7 +337,7 @@ static int fastcmp(const fastmatch_t *fg, const void *data,
* Fills in the good suffix table for SB/MB strings.
*/
#define FILL_BMGS \
if (!fg->hasdot) \
if (fg->len > 0 && !fg->hasdot) \
{ \
fg->sbmGs = malloc(fg->len * sizeof(int)); \
if (!fg->sbmGs) \
@ -353,7 +353,7 @@ static int fastcmp(const fastmatch_t *fg, const void *data,
* Fills in the good suffix table for wide strings.
*/
#define FILL_BMGS_WIDE \
if (!fg->hasdot) \
if (fg->wlen > 0 && !fg->hasdot) \
{ \
fg->bmGs = malloc(fg->wlen * sizeof(int)); \
if (!fg->bmGs) \