1#!/bin/sh 2 3# Copyright (C) 2008-2023 Free Software Foundation, Inc. 4 5# This program is free software: you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation, either version 3 of the License, or 8# (at your option) any later version. 9 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14 15# You should have received a copy of the GNU General Public License 16# along with this program. If not, see <https://www.gnu.org/licenses/>. 17 18. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 19print_ver_ ptx 20 21# Trigger a heap-clobbering bug in ptx from coreutils-6.10 and earlier. 22# Using a long file name makes an abort more likely. 23# Even with no file name, valgrind detects the buffer overrun. 24f=01234567890123456789012345678901234567890123456789 25touch $f empty || framework_failure_ 26 27# Specifying a regular expression ending in a lone backslash 28# would cause ptx to write beyond the end of a malloc'd buffer. 29ptx -F '\' $f < /dev/null > out || fail=1 30ptx -S 'foo\' $f < /dev/null >> out || fail=1 31ptx -W 'bar\\\' $f < /dev/null >> out || fail=1 32compare out empty || fail=1 33 34 35# Trigger an invalid heap reference noticed by gcc -fsanitize=address 36# from coreutils-8.22 and earlier. As well as an invalid memory reference, 37# the issue can be seen in the output, with nondeterministic whitespace 38# trimming when multiple files are specified. 39printf '%s\n' 'This is a ptx whitespace Trimming test' > ws.in 40ptx ws.in ws.in | sort | uniq -u > out 41compare /dev/null out || fail=1 42 43 44# Trigger an invalid heap reference noticed by gcc -fsanitize=address 45# from coreutils-8.25 and earlier. 46echo a > a 47ptx -w1 -A "$PWD/a" >/dev/null || fail=1 48 49Exit $fail 50