source: trunk/src/sed/testsuite/sandbox.sh@ 3670

Last change on this file since 3670 was 3613, checked in by bird, 10 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.5 KB
Line 
1#!/bin/sh
2# Test --sandbox mode
3
4# Copyright (C) 2016-2022 Free Software Foundation, Inc.
5
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <https://www.gnu.org/licenses/>.
18. "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed
19print_ver_ sed
20
21echo a > a || framework_failure_
22echo b > b || framework_failure_
23
24# Same error message, different character position in the sed program.
25for i in 1 6 14 ; do
26 err="sed: -e expression #1, char $i: e/r/w commands disabled in sandbox mode"
27 echo "$err" > exp-err$i || framework_failure_
28done
29
30# read command - without sandbox
31printf "a\nb\n" > exp || framework_failure_
32sed rb a > out || fail=1
33compare exp out || fail=1
34
35# read command - with sandbox
36returns_ 1 sed --sandbox -e 'ra' b >/dev/null 2>err1 || fail=1
37compare exp-err1 err1 || fail=1
38
39
40# write command (create file 'c') - without sandbox
41sed wc a > out || fail=1
42compare a c || fail=1
43compare out a || fail=1
44
45# write command - with sandbox
46returns_ 1 sed --sandbox -e 'wd' a >/dev/null 2>err2 || fail=1
47compare exp-err1 err1 || fail=1
48# ensure file 'd' was not created
49test -e d && fail=1
50
51
52
53# execute command - without sandbox
54sed 'etouch e' b > out || fail=1
55compare b out || fail=1
56# ensure 'e' was created
57test -e e || fail=1
58
59# execute command - with sandbox
60returns_ 1 sed --sandbox -e 'etouch f' b >/dev/null 2>err3 || fail=1
61compare exp-err1 err3 || fail=1
62# ensure 'f' was not created
63test -e f && fail=1
64
65
66
67# substitute+write option - without sandbox
68sed 's/^//wg' a > out || fail=1
69test -e g || fail=1
70
71# substitute+write option - with sandbox
72returns_ 1 sed --sandbox 's/^//wh' a >/dev/null 2>err4 || fail=1
73compare exp-err6 err4 || fail=1
74# ensure file 'h' was not created
75test -e h && fail=1
76
77
78
79# substitute+execute option - without sandbox
80sed 's/.*/touch i/e' a > out || fail=1
81test -e i || fail=1
82
83# substitute+execute option - with sandbox
84returns_ 1 sed --sandbox 's/.*/touch j/e' a >/dev/null 2>err5 || fail=1
85compare exp-err14 err5 || fail=1
86# ensure file 'j' was not created
87test -e j && fail=1
88
89
90Exit $fail
Note: See TracBrowser for help on using the repository browser.