diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-02 21:00:59 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-02 21:00:59 +0200 |
commit | f50e14632f7be56da7a38937c887f77812803f70 (patch) | |
tree | 0d657554780661ab752ec04bd8ba56f469b31d63 | |
parent | abf755615e5f20c3bbe7534fa29c72fd684ea616 (diff) | |
download | busybox-w32-f50e14632f7be56da7a38937c887f77812803f70.tar.gz busybox-w32-f50e14632f7be56da7a38937c887f77812803f70.tar.bz2 busybox-w32-f50e14632f7be56da7a38937c887f77812803f70.zip |
ash: parser: Fix parameter expansion inside inner double quotes
Upstream email:
parser: Fix parameter expansion inside inner double quotes
The parsing of parameter expansion inside inner double quotes
breaks because we never look for ENDVAR while innerdq is true.
echo "${x#"${x+''}"''}
This patch fixes it by pushing the syntax stack if innerdq is
true and we enter a new parameter expansion.
This patch also fixes a corner case where a bad substitution error
occurs within arithmetic expansion.
Reported-by: Denys Vlasenko <vda.linux@googlemail.com>
Fixes: ab1cecb40478 (" parser: Add syntax stack for recursive...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
function old new delta
readtoken1 2880 2898 +18
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 6 | ||||
-rw-r--r-- | shell/ash_test/ash-quoting/quote_in_varexp1.right | 2 | ||||
-rwxr-xr-x | shell/ash_test/ash-quoting/quote_in_varexp1.tests | 2 |
3 files changed, 8 insertions, 2 deletions
diff --git a/shell/ash.c b/shell/ash.c index d82eba15f..ed1a4416c 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -12467,10 +12467,12 @@ parsesub: { | |||
12467 | pungetc(); | 12467 | pungetc(); |
12468 | } | 12468 | } |
12469 | 12469 | ||
12470 | if (newsyn == ARISYNTAX && subtype > VSNORMAL) | 12470 | if (newsyn == ARISYNTAX) |
12471 | newsyn = DQSYNTAX; | 12471 | newsyn = DQSYNTAX; |
12472 | 12472 | ||
12473 | if (newsyn != synstack->syntax) { | 12473 | if ((newsyn != synstack->syntax || synstack->innerdq) |
12474 | && subtype != VSNORMAL | ||
12475 | ) { | ||
12474 | synstack_push(&synstack, | 12476 | synstack_push(&synstack, |
12475 | synstack->prev ?: alloca(sizeof(*synstack)), | 12477 | synstack->prev ?: alloca(sizeof(*synstack)), |
12476 | newsyn); | 12478 | newsyn); |
diff --git a/shell/ash_test/ash-quoting/quote_in_varexp1.right b/shell/ash_test/ash-quoting/quote_in_varexp1.right new file mode 100644 index 000000000..99a0aea7c --- /dev/null +++ b/shell/ash_test/ash-quoting/quote_in_varexp1.right | |||
@@ -0,0 +1,2 @@ | |||
1 | '' | ||
2 | Ok:0 | ||
diff --git a/shell/ash_test/ash-quoting/quote_in_varexp1.tests b/shell/ash_test/ash-quoting/quote_in_varexp1.tests new file mode 100755 index 000000000..1b97b0556 --- /dev/null +++ b/shell/ash_test/ash-quoting/quote_in_varexp1.tests | |||
@@ -0,0 +1,2 @@ | |||
1 | x="''''"; echo "${x#"${x+''}"''}" | ||
2 | echo Ok:$? | ||