| 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
|
|---|
| 19 | print_ver_ sed
|
|---|
| 20 |
|
|---|
| 21 | echo a > a || framework_failure_
|
|---|
| 22 | echo b > b || framework_failure_
|
|---|
| 23 |
|
|---|
| 24 | # Same error message, different character position in the sed program.
|
|---|
| 25 | for 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_
|
|---|
| 28 | done
|
|---|
| 29 |
|
|---|
| 30 | # read command - without sandbox
|
|---|
| 31 | printf "a\nb\n" > exp || framework_failure_
|
|---|
| 32 | sed rb a > out || fail=1
|
|---|
| 33 | compare exp out || fail=1
|
|---|
| 34 |
|
|---|
| 35 | # read command - with sandbox
|
|---|
| 36 | returns_ 1 sed --sandbox -e 'ra' b >/dev/null 2>err1 || fail=1
|
|---|
| 37 | compare exp-err1 err1 || fail=1
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | # write command (create file 'c') - without sandbox
|
|---|
| 41 | sed wc a > out || fail=1
|
|---|
| 42 | compare a c || fail=1
|
|---|
| 43 | compare out a || fail=1
|
|---|
| 44 |
|
|---|
| 45 | # write command - with sandbox
|
|---|
| 46 | returns_ 1 sed --sandbox -e 'wd' a >/dev/null 2>err2 || fail=1
|
|---|
| 47 | compare exp-err1 err1 || fail=1
|
|---|
| 48 | # ensure file 'd' was not created
|
|---|
| 49 | test -e d && fail=1
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 | # execute command - without sandbox
|
|---|
| 54 | sed 'etouch e' b > out || fail=1
|
|---|
| 55 | compare b out || fail=1
|
|---|
| 56 | # ensure 'e' was created
|
|---|
| 57 | test -e e || fail=1
|
|---|
| 58 |
|
|---|
| 59 | # execute command - with sandbox
|
|---|
| 60 | returns_ 1 sed --sandbox -e 'etouch f' b >/dev/null 2>err3 || fail=1
|
|---|
| 61 | compare exp-err1 err3 || fail=1
|
|---|
| 62 | # ensure 'f' was not created
|
|---|
| 63 | test -e f && fail=1
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 | # substitute+write option - without sandbox
|
|---|
| 68 | sed 's/^//wg' a > out || fail=1
|
|---|
| 69 | test -e g || fail=1
|
|---|
| 70 |
|
|---|
| 71 | # substitute+write option - with sandbox
|
|---|
| 72 | returns_ 1 sed --sandbox 's/^//wh' a >/dev/null 2>err4 || fail=1
|
|---|
| 73 | compare exp-err6 err4 || fail=1
|
|---|
| 74 | # ensure file 'h' was not created
|
|---|
| 75 | test -e h && fail=1
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 | # substitute+execute option - without sandbox
|
|---|
| 80 | sed 's/.*/touch i/e' a > out || fail=1
|
|---|
| 81 | test -e i || fail=1
|
|---|
| 82 |
|
|---|
| 83 | # substitute+execute option - with sandbox
|
|---|
| 84 | returns_ 1 sed --sandbox 's/.*/touch j/e' a >/dev/null 2>err5 || fail=1
|
|---|
| 85 | compare exp-err14 err5 || fail=1
|
|---|
| 86 | # ensure file 'j' was not created
|
|---|
| 87 | test -e j && fail=1
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 | Exit $fail
|
|---|