VirtualBox

source: kBuild/vendor/grep/3.7/tests/stack-overflow@ 3576

Last change on this file since 3576 was 3529, checked in by bird, 3 years ago

Imported grep 3.7 from grep-3.7.tar.gz (sha256: c22b0cf2d4f6bbe599c902387e8058990e1eee99aef333a203829e5fd3dbb342), applying minimal auto-props.

  • Property svn:executable set to *
File size: 2.0 KB
Line 
1#!/bin/sh
2# Ensure a stack overflow no longer segfaults
3
4. "${srcdir=.}/init.sh"; path_prepend_ ../src
5
6case $host_triplet in
7 *-midnightbsd*)
8 skip_ 'our stack-overflow detection does not work on this system';;
9esac
10
11# When compiled with ASAN, skip this test, because (on Fedora 32) it
12# would fail due to output like this on stderr:
13# +==2176827==WARNING: ASan is ignoring requested __asan_handle_no_return:
14# stack top: 0x7ffc48f20000; bottom 0x000000e25000; size: 0x7ffc480fb000 (140721517473792)
15# +False positive error reports may follow
16# +For details see https://github.com/google/sanitizers/issues/189
17ASAN_OPTIONS=help=true grep --version 2>&1 | grep -q AddressSanitizer \
18 && skip_ 'avoid false failure when built with ASAN'
19
20echo grep: stack overflow > exp || framework_failure_
21
22# Limit stack size. Otherwise, it appears to be too hard to overflow the
23# stack on some systems like gcc113, aarch64/linux-3.13.0 with 32GB of RAM
24# and 20GB of swap.
25ulimit -s 8192 2>/dev/null
26
27# grep attempts to detect overflow via gnulib's c-stack module.
28# Trigger that with an input regex composed solely of open parentheses,
29# increasing the size of that input until grep emits the expected diagnostic.
30fail=0
31for i in 1 3 5 10 20 30 40 50 100 200 400 1000; do
32 # Create a file containing $i * 10000 open parentheses:
33 printf %0${i}0000d 0|tr 0 '(' > in || framework_failure_
34 grep -E -f in >out 2>err; st=$?
35 if grep -q 'stack overflow' err; then
36 test $st = 2 || fail=1
37 compare /dev/null out || fail=1
38 compare exp err || fail=1
39 test $fail = 0 && Exit 0
40 fail_ 'printed "stack overflow", but something else was wrong'
41 fi
42done
43
44# If there was no stack overflow message and the final run exited with
45# status 1 and both stdout and stderr were empty, then assume it's a working
46# regex that avoids the internal stack overflow problem like glibc's regexp
47# used to.
48test $st = 1 \
49 && ! test -s out \
50 && ! test -s err \
51 && Exit 0
52
53fail_ 'grep never printed "stack overflow"'
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette