summaryrefslogtreecommitdiffstats
path: root/tools/regression
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-08-15 21:06:53 +0000
committerjilles <jilles@FreeBSD.org>2010-08-15 21:06:53 +0000
commit0328c8f214dbaa310380c458939f9e4448034c61 (patch)
tree620517973602d815bb3ce3bfb1defa5a51ba823e /tools/regression
parent380ff6898aebf17296366587520525edc0ca6935 (diff)
downloadFreeBSD-src-0328c8f214dbaa310380c458939f9e4448034c61.zip
FreeBSD-src-0328c8f214dbaa310380c458939f9e4448034c61.tar.gz
sh: Fix break/continue/return sometimes not skipping the rest of dot script.
In our implementation and most others, a break or continue in a dot script can break or continue a loop outside the dot script. This should cause all further commands in the dot script to be skipped. However, cmdloop() did not know about this and continued to parse and execute commands from the dot script. As described in the man page, a return in a dot script in a function returns from the function, not only from the dot script. There was a similar issue as with break and continue. In various other shells, the return appears to return from the dot script, but POSIX seems not very clear about this.
Diffstat (limited to 'tools/regression')
-rw-r--r--tools/regression/bin/sh/builtins/break1.016
-rw-r--r--tools/regression/bin/sh/builtins/return5.017
2 files changed, 33 insertions, 0 deletions
diff --git a/tools/regression/bin/sh/builtins/break1.0 b/tools/regression/bin/sh/builtins/break1.0
new file mode 100644
index 0000000..ba0cbb4
--- /dev/null
+++ b/tools/regression/bin/sh/builtins/break1.0
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+if [ "$1" != nested ]; then
+ while :; do
+ set -- nested
+ . "$0"
+ echo bad2
+ exit 2
+ done
+ exit 0
+fi
+# To trigger the bug, the following commands must be at the top level,
+# with newlines in between.
+break
+echo bad1
+exit 1
diff --git a/tools/regression/bin/sh/builtins/return5.0 b/tools/regression/bin/sh/builtins/return5.0
new file mode 100644
index 0000000..6e4b7bd
--- /dev/null
+++ b/tools/regression/bin/sh/builtins/return5.0
@@ -0,0 +1,17 @@
+# $FreeBSD$
+
+if [ "$1" != nested ]; then
+ f() {
+ set -- nested
+ . "$0"
+ # Allow return to return from the function or the dot script.
+ return 4
+ }
+ f
+ exit $(($? ^ 4))
+fi
+# To trigger the bug, the following commands must be at the top level,
+# with newlines in between.
+return 4
+echo bad
+exit 1
OpenPOWER on IntegriCloud