ash: only allow local variables in functions
authorRon Yorston <rmy@pobox.com>
Thu, 29 Oct 2015 16:19:14 +0000 (16:19 +0000)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 29 Oct 2015 19:33:44 +0000 (20:33 +0100)
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash.c
shell/ash_test/ash-misc/local2.right [new file with mode: 0644]
shell/ash_test/ash-misc/local2.tests [new file with mode: 0755]

index a2e06184b09d6294fdb13ea0671f3df269b897c0..0d7cac0b59bdc21e7b0a7f5abf7a0349d47b3f19 100644 (file)
@@ -8987,6 +8987,9 @@ localcmd(int argc UNUSED_PARAM, char **argv)
 {
        char *name;
 
+       if (!funcnest)
+               ash_msg_and_raise_error("not in a function");
+
        argv = argptr;
        while ((name = *argv++) != NULL) {
                mklocal(name);
diff --git a/shell/ash_test/ash-misc/local2.right b/shell/ash_test/ash-misc/local2.right
new file mode 100644 (file)
index 0000000..630ef79
--- /dev/null
@@ -0,0 +1 @@
+./local2.tests: local: line 1: not in a function
diff --git a/shell/ash_test/ash-misc/local2.tests b/shell/ash_test/ash-misc/local2.tests
new file mode 100755 (executable)
index 0000000..8e14037
--- /dev/null
@@ -0,0 +1 @@
+local x=1