[PATCH] ash: only allow local variables in functions

Ron Yorston rmy at pobox.com
Thu Oct 29 16:19:14 UTC 2015


Signed-off-by: Ron Yorston <rmy at pobox.com>
---
 shell/ash.c                          | 3 +++
 shell/ash_test/ash-misc/local2.right | 1 +
 shell/ash_test/ash-misc/local2.tests | 1 +
 3 files changed, 5 insertions(+)
 create mode 100644 shell/ash_test/ash-misc/local2.right
 create mode 100755 shell/ash_test/ash-misc/local2.tests

diff --git a/shell/ash.c b/shell/ash.c
index 9d0226c..cfb313a 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -8982,6 +8982,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
index 0000000..630ef79
--- /dev/null
+++ b/shell/ash_test/ash-misc/local2.right
@@ -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
index 0000000..8e14037
--- /dev/null
+++ b/shell/ash_test/ash-misc/local2.tests
@@ -0,0 +1 @@
+local x=1
-- 
2.4.3



More information about the busybox mailing list