]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
bsdgrep: Don't allow negative context flags, add more tests
authorkevans <kevans@FreeBSD.org>
Thu, 17 Aug 2017 04:04:42 +0000 (04:04 +0000)
committerkevans <kevans@FreeBSD.org>
Thu, 17 Aug 2017 04:04:42 +0000 (04:04 +0000)
commite4d500149703035432c35df48506b8bf7237edef
tree53ca9330cb1525c6df9eec4c40de5d4a7f30faf1
parent464673b5a2312eb0d7b4c7b2add16a1f2aa77e69
bsdgrep: Don't allow negative context flags, add more tests

MFC r318302: 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.

MFC r318317: bsdgrep: add more tests for different binary flags

The existing 'binary' test in netbsd-tests/ does a basic check of the
default treatment for binary behavior, but not much more than that.
Given some opportunity for breakage recently that did not trigger any
failures, add some tests to cover the three different binary file
behaviors (a, -I, -U) and their --binary-files= equivalent values.

Approved by: emaste (mentor, blanket MFC)
contrib/netbsd-tests/usr.bin/grep/t_grep.sh
usr.bin/grep/grep.c
usr.bin/grep/grep.h
usr.bin/grep/queue.c
usr.bin/grep/util.c