diff options
| author | Bernhard Voelker <mail@bernhard-voelker.de> | 2021-11-24 23:59:00 +0100 |
|---|---|---|
| committer | Bernhard Voelker <mail@bernhard-voelker.de> | 2021-11-26 01:06:15 +0100 |
| commit | d50912b6c60732476bb2955d947bacb73aaa2d59 (patch) | |
| tree | 40f566070118f7577f3f6088a816f5f74010066f | |
| parent | 64f5221ef20ba6723f2b0d5f8c9b666f46480451 (diff) | |
test-framework-sh: remove unsafe entries from PATH
Running tests with '.' in the PATH may yield unspecified results,
and is deemed unsafe per se. This includes empty entries as well
which are treated like a '.' entry as per POSIX.
* tests/init.sh (setup_): Add snippet to remove relative and non-
accessible entries from the PATH environment variable.
| -rw-r--r-- | ChangeLog | 9 | ||||
| -rw-r--r-- | tests/init.sh | 17 |
2 files changed, 26 insertions, 0 deletions
@@ -1,3 +1,12 @@ +2021-11-25 Bernhard Voelker <mail@bernhard-voelker.de> + + test-framework-sh: remove unsafe entries from PATH + Running tests with '.' in the PATH may yield unspecified results, + and is deemed unsafe per se. This includes empty entries as well + which are treated like a '.' entry as per POSIX. + * tests/init.sh (setup_): Add snippet to remove relative and non- + accessible entries from the PATH environment variable. + 2021-11-24 Paul Eggert <eggert@cs.ucla.edu> regex: merge from glibc diff --git a/tests/init.sh b/tests/init.sh index 9ef8348..a975592 100644 --- a/tests/init.sh +++ b/tests/init.sh @@ -426,6 +426,23 @@ setup_ () for sig_ in 1 2 3 13 15; do eval "trap 'Exit $(expr $sig_ + 128)' $sig_" done + + # Remove relative and non-accessible directories from PATH, including '.' + # and Zero-length entries. + saved_IFS="$IFS" + IFS=: + new_PATH= + sep_= + for dir in $PATH; do + case "$dir" in + /*) test -d "$dir/." || continue + new_PATH="${new_PATH}${sep_}${dir}" + sep_=':';; + esac + done + IFS="$saved_IFS" + PATH="$new_PATH" + export PATH } # This is a stub function that is run upon trap (upon regular exit and |
