summaryrefslogtreecommitdiffstats
path: root/bin/sh/tests
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2016-01-07 20:48:24 +0000
committerjilles <jilles@FreeBSD.org>2016-01-07 20:48:24 +0000
commit68a5d0c3723e6c46981d075e62545db7e77d6aed (patch)
tree1f4c8334bb40e57e4039768bcf7bafa2aade0d0e /bin/sh/tests
parentc0f429aa4730019664e517ed418f6c19e1e63a2d (diff)
downloadFreeBSD-src-68a5d0c3723e6c46981d075e62545db7e77d6aed.zip
FreeBSD-src-68a5d0c3723e6c46981d075e62545db7e77d6aed.tar.gz
sh: Ensure OPTIND=1 in subshell without forking does not affect outer env.
Command substitutions containing a single simple command and here-document expansion are performed in a subshell environment, but may not fork. Any modified state of the shell environment should be restored afterward. The state that OPTIND=1 had been done was not saved and restored here. Note that the other parts of shellparam need not be saved and restored, since they are not modified in these situations (a fork is done before such modifications).
Diffstat (limited to 'bin/sh/tests')
-rw-r--r--bin/sh/tests/builtins/Makefile1
-rw-r--r--bin/sh/tests/builtins/getopts10.011
2 files changed, 12 insertions, 0 deletions
diff --git a/bin/sh/tests/builtins/Makefile b/bin/sh/tests/builtins/Makefile
index 63e6ab5..750e615 100644
--- a/bin/sh/tests/builtins/Makefile
+++ b/bin/sh/tests/builtins/Makefile
@@ -95,6 +95,7 @@ FILES+= getopts6.0
FILES+= getopts7.0
FILES+= getopts8.0 getopts8.0.stdout
FILES+= getopts9.0 getopts9.0.stdout
+FILES+= getopts10.0
FILES+= hash1.0 hash1.0.stdout
FILES+= hash2.0 hash2.0.stdout
FILES+= hash3.0 hash3.0.stdout
diff --git a/bin/sh/tests/builtins/getopts10.0 b/bin/sh/tests/builtins/getopts10.0
new file mode 100644
index 0000000..a88e6ca
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts10.0
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+set -- -x arg
+opt=not
+getopts x opt
+r1=$? OPTIND1=$OPTIND opt1=$opt
+: $(: $((OPTIND = 1)))
+getopts x opt
+r2=$? OPTIND2=$OPTIND
+[ "$r1" = 0 ] && [ "$OPTIND1" = 2 ] && [ "$opt1" = x ] && [ "$r2" != 0 ] &&
+ [ "$OPTIND2" = 2 ]
OpenPOWER on IntegriCloud