freebsd-dev/usr.bin/grep
Ed Maste b5fc583c27 bsdgrep: don't allow negative -A / -B / -C
Previously, when given a negative -A/-B/-C argument bsdgrep would
overflow the respective context flag(s) and exhibited surprising
behavior.

Fix this by removing unsignedness of Aflag/Bflag and erroring out if
we're given a value < 0.  Also adjust the type used to track 'tail'
context in procfile() so that it accurately reflects the Aflag value
rather than overflowing and losing trailing context.

This also fixes an inconsistency previously existing between -n and
-C "n" behavior.  They are now both limited to LLONG_MAX, to be
consistent.

Add some test cases to make sure grep errors out properly for both
negative context values as well as non-numeric context values rather
than giving bogus matches.

Submitted by:	Kyle Evans <kevans91@ksu.edu>
Reviewed by:	cem
Differential Revision:	https://reviews.freebsd.org/D10675
2017-05-15 17:51:01 +00:00
..
nls bsdgrep: correct nls usage data after r317049 2017-05-02 13:47:15 +00:00
regex bsdgrep: fix escape map building for multibyte strings 2017-05-02 20:44:06 +00:00
tests bsdgrep: fix -w flag matching with an empty pattern 2017-05-02 20:39:33 +00:00
file.c bsdgrep: add -z/--null-data support 2017-04-17 13:14:18 +00:00
grep.1 bsdgrep: add -z/--null-data support 2017-04-17 13:14:18 +00:00
grep.c bsdgrep: don't allow negative -A / -B / -C 2017-05-15 17:51:01 +00:00
grep.h bsdgrep: don't allow negative -A / -B / -C 2017-05-15 17:51:01 +00:00
Makefile bsdgrep: Add GNU compatible version string indicator 2017-05-02 13:38:20 +00:00
Makefile.depend DIRDEPS_BUILD: Update dependencies. 2017-05-09 01:48:23 +00:00
queue.c bsdgrep: don't allow negative -A / -B / -C 2017-05-15 17:51:01 +00:00
util.c bsdgrep: don't allow negative -A / -B / -C 2017-05-15 17:51:01 +00:00