VirtualBox

source: kBuild/trunk/src/sed/testsuite/bug32082.sh@ 3613

Last change on this file since 3613 was 3613, checked in by bird, 7 months ago

src/sed: Merged in changes between 4.1.5 and 4.9 from the vendor branch. (svn merge /vendor/sed/4.1.5 /vendor/sed/current .)

  • Property svn:executable set to *
File size: 2.7 KB
Line 
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
21print_ver_ sed
22
23require_valgrind_
24
25printf '1\n2\n' > in || framework_failure_
26printf '1\n2\n\n' > exp-posix || framework_failure_
27printf '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
36valgrind --quiet --error-exitcode=1 \
37 sed --posix -e '/2/p ; 2s//\9/' in > out-posix 2> err-posix || fail=1
38
39echo "valgrind report for 'posix' test:"
40echo "=================================="
41cat err-posix
42echo "=================================="
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
47grep 'valgrind: .*Assertion.*failed' err-posix > /dev/null \
48 && skip_ 'you seem to have a buggy version of valgrind'
49
50compare exp-posix out-posix || fail=1
51compare /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
64valgrind --quiet --error-exitcode=1 \
65 sed -e '/^/s///p ; 2s//\9/' in > out-no-posix 2> err-no-posix || fail=1
66
67echo "valgrind report for 'no-posix' test:"
68echo "===================================="
69cat err-no-posix
70echo "===================================="
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
74grep 'valgrind: .*Assertion.*failed' err-no-posix > /dev/null \
75 && skip_ 'you seem to have a buggy version of valgrind'
76
77compare exp-no-posix out-no-posix || fail=1
78compare /dev/null err || fail=1
79
80
81Exit $fail
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