summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests
diff options
context:
space:
mode:
authorkevans <kevans@FreeBSD.org>2017-08-17 04:18:31 +0000
committerkevans <kevans@FreeBSD.org>2017-08-17 04:18:31 +0000
commit66ff5b080a97728a17f338222b1bec9dff646980 (patch)
tree328cfdef7c173533a5e05cbd25a60faf4103ef1f /contrib/netbsd-tests
parente4d500149703035432c35df48506b8bf7237edef (diff)
downloadFreeBSD-src-66ff5b080a97728a17f338222b1bec9dff646980.zip
FreeBSD-src-66ff5b080a97728a17f338222b1bec9dff646980.tar.gz
bsdgrep: fix segfault with --mmap and add relevant test
MFC r318565: bsdgrep: fix segfault with --mmap r313948 partially fixed --mmap behavior but was incomplete. This commit generally reverts it and does it the more correct way- by just consuming the rest of the buffer and moving on. MFC r318908: bsdgrep: add --mmap tests Basic sanity tests as well as coverage for the bug fixed in r318565. PR: 219402 Approved by: emaste (mentor, blanket MFC)
Diffstat (limited to 'contrib/netbsd-tests')
-rwxr-xr-xcontrib/netbsd-tests/usr.bin/grep/t_grep.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/contrib/netbsd-tests/usr.bin/grep/t_grep.sh b/contrib/netbsd-tests/usr.bin/grep/t_grep.sh
index 05d06f6..6907401 100755
--- a/contrib/netbsd-tests/usr.bin/grep/t_grep.sh
+++ b/contrib/netbsd-tests/usr.bin/grep/t_grep.sh
@@ -574,6 +574,46 @@ binary_flags_body()
atf_check -o inline:"A\000B\000C\n" grep --binary-files=text 'B' test1
atf_check -s exit:1 grep --binary-files=without-match 'B' test2
}
+
+atf_test_case mmap
+mmap_head()
+{
+ atf_set "descr" "Check basic matching with --mmap flag"
+}
+mmap_body()
+{
+ grep_type
+ if [ $? -eq $GREP_TYPE_GNU ]; then
+ atf_expect_fail "gnu grep from ports has no --mmap option"
+ fi
+
+ printf "A\nB\nC\n" > test1
+
+ atf_check -s exit:0 -o inline:"B\n" grep --mmap -oe "B" test1
+ atf_check -s exit:1 grep --mmap -e "Z" test1
+}
+
+atf_test_case mmap_eof_not_eol
+mmap_eof_not_eol_head()
+{
+ atf_set "descr" "Check --mmap flag handling of encountering EOF without EOL (PR 165471, 219402)"
+}
+mmap_eof_not_eol_body()
+{
+ grep_type
+ if [ $? -eq $GREP_TYPE_GNU ]; then
+ atf_expect_fail "gnu grep from ports has no --mmap option"
+ fi
+
+ printf "ABC" > test1
+ jot -b " " -s "" 4096 >> test2
+
+ atf_check -s exit:0 -o inline:"B\n" grep --mmap -oe "B" test1
+ # Dependency on jemalloc(3) to detect buffer overflow, otherwise this
+ # unreliably produces a SIGSEGV or SIGBUS
+ atf_check -s exit:0 -o not-empty \
+ env MALLOC_CONF="redzone:true" grep --mmap -e " " test2
+}
# End FreeBSD
atf_init_test_cases()
@@ -610,5 +650,7 @@ atf_init_test_cases()
atf_add_test_case grep_nomatch_flags
atf_add_test_case binary_flags
atf_add_test_case badcontext
+ atf_add_test_case mmap
+ atf_add_test_case mmap_eof_not_eol
# End FreeBSD
}
OpenPOWER on IntegriCloud