[klibc] [klibc:update-dash] dash: parser: Do not push token back before parseheredoc

klibc-bot for Herbert Xu herbert at gondor.apana.org.au
Sat Mar 28 14:49:35 PDT 2020


Commit-ID:  e94b6379eb4db14efb17de19c411ea53d778fca3
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=e94b6379eb4db14efb17de19c411ea53d778fca3
Author:     Herbert Xu <herbert at gondor.apana.org.au>
AuthorDate: Mon, 19 Nov 2018 18:43:58 +0800
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Sat, 28 Mar 2020 21:42:55 +0000

[klibc] dash: parser: Do not push token back before parseheredoc

[ dash commit 2c3ba509eb8117894d515e8fffc94aa099f38f8a ]

When we read the first token in list() we use peektoken instead
of readtoken as the following code needs to use the same token
again.  However, this is wrong when we're in a here-document as
it will clobber the saved token without resetting the tokpushback
flag.

This patch fixes it by doing the tokpushback after parseheredoc
and setting lasttoken again if parseheredoc was called.

Reported-by: Ron Yorston <rmy at frippery.org>
Fixes: 7c245aa8ed33 ("[PARSER] Simplify EOF/newline handling in...")
Fixes: ee5cbe9fd6bc ("[SHELL] Optimize dash -c "command" to avoid a fork")
Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au>
Tested-by: Simon Ser <contact at emersion.fr>
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

---
 usr/dash/parser.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/usr/dash/parser.c b/usr/dash/parser.c
index c4e63781..1f9e8ec0 100644
--- a/usr/dash/parser.c
+++ b/usr/dash/parser.c
@@ -166,7 +166,7 @@ list(int nlflag)
 
 	n1 = NULL;
 	for (;;) {
-		switch (peektoken()) {
+		switch (readtoken()) {
 		case TNL:
 			if (!(nlflag & 1))
 				break;
@@ -177,9 +177,12 @@ list(int nlflag)
 			if (!n1 && (nlflag & 1))
 				n1 = NEOF;
 			parseheredoc();
+			tokpushback++;
+			lasttoken = TEOF;
 			return n1;
 		}
 
+		tokpushback++;
 		checkkwd = CHKNL | CHKKWD | CHKALIAS;
 		if (nlflag == 2 && tokendlist[peektoken()])
 			return n1;


More information about the klibc mailing list