1 | #!/bin/sh
|
---|
2 | # sed would access uninitialized memory for certain invalid backreference uses.
|
---|
3 | # Before sed 4.6 these would result in "Invalid read size of 4" reported
|
---|
4 | # by valgrind from execute.c:992
|
---|
5 |
|
---|
6 | # Copyright (C) 2018-2022 Free Software Foundation, Inc.
|
---|
7 |
|
---|
8 | # This program is free software: you can redistribute it and/or modify
|
---|
9 | # it under the terms of the GNU General Public License as published by
|
---|
10 | # the Free Software Foundation, either version 3 of the License, or
|
---|
11 | # (at your option) any later version.
|
---|
12 |
|
---|
13 | # This program is distributed in the hope that it will be useful,
|
---|
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | # GNU General Public License for more details.
|
---|
17 |
|
---|
18 | # You should have received a copy of the GNU General Public License
|
---|
19 | # along with this program. If not, see <https://www.gnu.org/licenses/>.
|
---|
20 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed
|
---|
21 | print_ver_ sed
|
---|
22 |
|
---|
23 | require_valgrind_
|
---|
24 |
|
---|
25 | printf '1\n2\n' > in || framework_failure_
|
---|
26 | printf '1\n2\n\n' > exp-posix || framework_failure_
|
---|
27 | printf '1\n1\n2\n2\n' > exp-no-posix || framework_failure_
|
---|
28 |
|
---|
29 | #
|
---|
30 | # Test 1: with "--posix"
|
---|
31 | #
|
---|
32 | # using "--posix" disables the backref safety check in
|
---|
33 | # regexp.c:compile_regex_1(), which is reported as:
|
---|
34 | # "invalid reference \\%d on `s' command's RHS"
|
---|
35 |
|
---|
36 | valgrind --quiet --error-exitcode=1 \
|
---|
37 | sed --posix -e '/2/p ; 2s//\9/' in > out-posix 2> err-posix || fail=1
|
---|
38 |
|
---|
39 | echo "valgrind report for 'posix' test:"
|
---|
40 | echo "=================================="
|
---|
41 | cat err-posix
|
---|
42 | echo "=================================="
|
---|
43 |
|
---|
44 |
|
---|
45 | # Work around a bug in CentOS 5.10's valgrind
|
---|
46 | # FIXME: remove in 2018 or when CentOS 5 is no longer officially supported
|
---|
47 | grep 'valgrind: .*Assertion.*failed' err-posix > /dev/null \
|
---|
48 | && skip_ 'you seem to have a buggy version of valgrind'
|
---|
49 |
|
---|
50 | compare exp-posix out-posix || fail=1
|
---|
51 | compare /dev/null err || fail=1
|
---|
52 |
|
---|
53 |
|
---|
54 |
|
---|
55 | #
|
---|
56 | # Test 2: without "--posix"
|
---|
57 | #
|
---|
58 | # When not using "--posix", using a backref to a non-existing group
|
---|
59 | # would be caught in compile_regex_1.
|
---|
60 | # As reported in bugs.gnu.org/32082 by [email protected],
|
---|
61 | # using the recent begline/endline optimization with a few "previous regex"
|
---|
62 | # tricks bypasses this check.
|
---|
63 |
|
---|
64 | valgrind --quiet --error-exitcode=1 \
|
---|
65 | sed -e '/^/s///p ; 2s//\9/' in > out-no-posix 2> err-no-posix || fail=1
|
---|
66 |
|
---|
67 | echo "valgrind report for 'no-posix' test:"
|
---|
68 | echo "===================================="
|
---|
69 | cat err-no-posix
|
---|
70 | echo "===================================="
|
---|
71 |
|
---|
72 | # Work around a bug in CentOS 5.10's valgrind
|
---|
73 | # FIXME: remove in 2018 or when CentOS 5 is no longer officially supported
|
---|
74 | grep 'valgrind: .*Assertion.*failed' err-no-posix > /dev/null \
|
---|
75 | && skip_ 'you seem to have a buggy version of valgrind'
|
---|
76 |
|
---|
77 | compare exp-no-posix out-no-posix || fail=1
|
---|
78 | compare /dev/null err || fail=1
|
---|
79 |
|
---|
80 |
|
---|
81 | Exit $fail
|
---|