diff options
author | Jilles Tjoelker <jilles@FreeBSD.org> | 2010-12-30 22:33:55 +0000 |
---|---|---|
committer | Jilles Tjoelker <jilles@FreeBSD.org> | 2010-12-30 22:33:55 +0000 |
commit | 11535bdf041a8f23b9a4aea01b7594e3a39ffa81 (patch) | |
tree | b19941413f90ce2a9c354cf3bdd679a5f201afe2 /tools/regression/bin/sh/expansion/cmdsubst10.0 | |
parent | 20b07a4d851fb7da5f16b66fcdc15a00ef116e5a (diff) | |
download | src-11535bdf041a8f23b9a4aea01b7594e3a39ffa81.tar.gz src-11535bdf041a8f23b9a4aea01b7594e3a39ffa81.zip |
sh: Avoid side effects from builtins in optimized command substitution.
Change the criterion for builtins to be safe to execute in the same process
in optimized command substitution from a blacklist of only cd, . and eval to
a whitelist.
This avoids clobbering the main shell environment such as by $(exit 4) and
$(set -x).
The builtins jobid, jobs, times and trap can still show information not
available in a child process; this is deliberately permitted. (Changing
traps is not.)
For some builtins, whether they are safe depends on the arguments passed to
them. Some of these are always considered unsafe to keep things simple; this
only harms efficiency a little in the rare case they are used alone in a
command substitution.
Notes
Notes:
svn path=/head/; revision=216826
Diffstat (limited to 'tools/regression/bin/sh/expansion/cmdsubst10.0')
-rw-r--r-- | tools/regression/bin/sh/expansion/cmdsubst10.0 | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/regression/bin/sh/expansion/cmdsubst10.0 b/tools/regression/bin/sh/expansion/cmdsubst10.0 new file mode 100644 index 000000000000..7cf17a3e8fe1 --- /dev/null +++ b/tools/regression/bin/sh/expansion/cmdsubst10.0 @@ -0,0 +1,51 @@ +# $FreeBSD$ + +a1=$(alias) +: $(alias testalias=abcd) +a2=$(alias) +[ "$a1" = "$a2" ] || echo Error at line $LINENO + +alias testalias2=abcd +a1=$(alias) +: $(unalias testalias2) +a2=$(alias) +[ "$a1" = "$a2" ] || echo Error at line $LINENO + +[ "$(command -V pwd)" = "$(command -V pwd; exit $?)" ] || echo Error at line $LINENO + +v=1 +: $(export v=2) +[ "$v" = 1 ] || echo Error at line $LINENO + +rotest=1 +: $(readonly rotest=2) +[ "$rotest" = 1 ] || echo Error at line $LINENO + +set +u +: $(set -u) +case $- in +*u*) echo Error at line $LINENO ;; +esac +set +u + +set +u +: $(set -o nounset) +case $- in +*u*) echo Error at line $LINENO ;; +esac +set +u + +set +u +: $(command set -u) +case $- in +*u*) echo Error at line $LINENO ;; +esac +set +u + +umask 77 +u1=$(umask) +: $(umask 022) +u2=$(umask) +[ "$u1" = "$u2" ] || echo Error at line $LINENO + +dummy=$(exit 3); [ $? -eq 3 ] || echo Error at line $LINENO |