summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJim Meyering <meyering@fb.com>2017-12-12 09:05:55 -0800
committerJim Meyering <meyering@fb.com>2017-12-16 11:28:52 -0800
commit51ef8adb2f7eeb073ba98be4f6baf56817e4d358 (patch)
tree6816cde93dfe6eedce330ad4ceccc57942c9e1aa /tests
parent6ada8b0a1b3f408ebf76e0cf7f7bb61019a70fdc (diff)
downloadgrep-51ef8adb2f7eeb073ba98be4f6baf56817e4d358.tar.gz
grep: diagnose stack overflow rather than segfaulting
* bootstrap.conf (gnulib_modules): Add c-stack. * src/grep.c: Include "c-stack.h". (main): Call c_stack_action (NULL); * tests/stack-overflow: New file. * tests/Makefile.am (TESTS): Add name of new file. * NEWS (Improvements): Mention it. Interestingly, this bug does not afflict grep-2.5.4 or prior, so it appeared to have been introduced with grep-2.6. However, the origin is in glibc's regexp compiler, and I tracked it to stack-aware parsing that was removed from glibc's regexp in 2002. However, grep-2.5.4 was released in 2009. That version worked (and still works, now) because it included and (by default) used an old copy of glibc's regexp code. Jeremy Feusi reported the grep segfault in https://bugs.gnu.org/29666. I reported the glibc regexp bug in https://sourceware.org/bugzilla/show_bug.cgi?id=22620
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rwxr-xr-xtests/stack-overflow16
2 files changed, 17 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 66fb4617..4aca63b3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -151,6 +151,7 @@ TESTS = \
skip-read \
spencer1 \
spencer1-locale \
+ stack-overflow \
status \
surrogate-pair \
symlink \
diff --git a/tests/stack-overflow b/tests/stack-overflow
new file mode 100755
index 00000000..2042ebc5
--- /dev/null
+++ b/tests/stack-overflow
@@ -0,0 +1,16 @@
+#!/bin/sh
+# Ensure a stack overflow no longer segfaults
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+# Too many open parentheses.
+printf %080000d 0|tr 0 '(' > in || framework_failure_
+echo grep: stack overflow > exp || framework_failure_
+
+fail=0
+returns_ 2 grep -E -f in >out 2>err || fail=1
+
+compare /dev/null out || fail=1
+compare exp err || fail=1
+
+Exit $fail