summary refs log tree commit diff
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2018-04-03 01:04:55 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2018-04-19 18:19:30 +0800
commit48ca00863af909461d1372998bb90549f27abaaf (patch)
tree520593b8f7a0350d8ac3fd8016a2349935429b63
parentparser: Fix parsing of ${} (diff)
downloaddash-48ca00863af909461d1372998bb90549f27abaaf.tar.gz
dash-48ca00863af909461d1372998bb90549f27abaaf.zip
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>
-rw-r--r--src/parser.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/parser.c b/src/parser.c
index efa8060..8e40781 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1325,10 +1325,11 @@ badsub:
 			pungetc();
 		}
 
-		if (newsyn == ARISYNTAX && subtype > VSNORMAL)
+		if (newsyn == ARISYNTAX)
 			newsyn = DQSYNTAX;
 
-		if (newsyn != synstack->syntax) {
+		if ((newsyn != synstack->syntax || synstack->innerdq) &&
+		    subtype != VSNORMAL) {
 			synstack_push(&synstack,
 				      synstack->prev ?:
 				      alloca(sizeof(*synstack)),