aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-09-08 01:43:12 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-09-08 01:43:12 +0200
commit8c68ae8416c8b54222eb3cd1d4908a570147e134 (patch)
tree0da34e8659371340b1dfd5984043be00bde96ebb
parentc54025612711a6b1997efd99206b9fbcaa5a29cf (diff)
downloadbusybox-w32-8c68ae8416c8b54222eb3cd1d4908a570147e134.tar.gz
busybox-w32-8c68ae8416c8b54222eb3cd1d4908a570147e134.tar.bz2
busybox-w32-8c68ae8416c8b54222eb3cd1d4908a570147e134.zip
ash: parser: Fix alias expansion after heredoc or newlines
Upstream commit: Date: Wed, 29 Apr 2020 00:19:59 +1000 parser: Fix alias expansion after heredoc or newlines This script should print OK: alias a="case x in " b=x a b) echo BAD;; esac alias BEGIN={ END=} BEGIN cat <<- EOF > /dev/null $(:) EOF END : <<- EOF && $(:) EOF BEGIN echo OK END However, because the value of checkkwd is either zeroed when it shouldn't, or isn't zeroed when it should, dash currently gets it wrong in every case. This patch fixes it by saving checkkwd and zeroing it where needed. function old new delta readtoken 157 176 +19 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c7
-rw-r--r--shell/ash_test/ash-alias/alias_brace.right1
-rwxr-xr-xshell/ash_test/ash-alias/alias_brace.tests16
-rw-r--r--shell/ash_test/ash-alias/alias_case.right1
-rwxr-xr-xshell/ash_test/ash-alias/alias_case.tests8
5 files changed, 31 insertions, 2 deletions
diff --git a/shell/ash.c b/shell/ash.c
index f1c21188e..5a001b004 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -13265,10 +13265,14 @@ readtoken(void)
13265 if (kwd & CHKNL) { 13265 if (kwd & CHKNL) {
13266 while (t == TNL) { 13266 while (t == TNL) {
13267 parseheredoc(); 13267 parseheredoc();
13268 checkkwd = 0;
13268 t = xxreadtoken(); 13269 t = xxreadtoken();
13269 } 13270 }
13270 } 13271 }
13271 13272
13273 kwd |= checkkwd;
13274 checkkwd = 0;
13275
13272 if (t != TWORD || quoteflag) { 13276 if (t != TWORD || quoteflag) {
13273 goto out; 13277 goto out;
13274 } 13278 }
@@ -13287,7 +13291,7 @@ readtoken(void)
13287 } 13291 }
13288 } 13292 }
13289 13293
13290 if (checkkwd & CHKALIAS) { 13294 if (kwd & CHKALIAS) {
13291#if ENABLE_ASH_ALIAS 13295#if ENABLE_ASH_ALIAS
13292 struct alias *ap; 13296 struct alias *ap;
13293 ap = lookupalias(wordtext, 1); 13297 ap = lookupalias(wordtext, 1);
@@ -13300,7 +13304,6 @@ readtoken(void)
13300#endif 13304#endif
13301 } 13305 }
13302 out: 13306 out:
13303 checkkwd = 0;
13304#if DEBUG 13307#if DEBUG
13305 if (!alreadyseen) 13308 if (!alreadyseen)
13306 TRACE(("token '%s' %s\n", tokname_array[t], t == TWORD ? wordtext : "")); 13309 TRACE(("token '%s' %s\n", tokname_array[t], t == TWORD ? wordtext : ""));
diff --git a/shell/ash_test/ash-alias/alias_brace.right b/shell/ash_test/ash-alias/alias_brace.right
new file mode 100644
index 000000000..7326d9603
--- /dev/null
+++ b/shell/ash_test/ash-alias/alias_brace.right
@@ -0,0 +1 @@
Ok
diff --git a/shell/ash_test/ash-alias/alias_brace.tests b/shell/ash_test/ash-alias/alias_brace.tests
new file mode 100755
index 000000000..7571b64ac
--- /dev/null
+++ b/shell/ash_test/ash-alias/alias_brace.tests
@@ -0,0 +1,16 @@
1# Note: bash would need:
2#shopt -s expand_aliases
3# to enable aliases in non-interactive mode
4alias BEGIN={ END=}
5BEGIN
6 cat <<- EOF > /dev/null
7 $(:)
8 EOF
9END
10
11: <<- EOF &&
12 $(:)
13EOF
14BEGIN
15 echo Ok
16END
diff --git a/shell/ash_test/ash-alias/alias_case.right b/shell/ash_test/ash-alias/alias_case.right
new file mode 100644
index 000000000..7326d9603
--- /dev/null
+++ b/shell/ash_test/ash-alias/alias_case.right
@@ -0,0 +1 @@
Ok
diff --git a/shell/ash_test/ash-alias/alias_case.tests b/shell/ash_test/ash-alias/alias_case.tests
new file mode 100755
index 000000000..ed8275875
--- /dev/null
+++ b/shell/ash_test/ash-alias/alias_case.tests
@@ -0,0 +1,8 @@
1# Note: bash would need:
2#shopt -s expand_aliases
3# to enable aliases in non-interactive mode
4alias a="case x in " b=x
5a
6b) echo BAD;;
7*) echo Ok;;
8esac