diff mbox

parser: Save/restore here-documents in command substitution

Message ID 20180507171403.xrfkhbqmze4p27xo@gondor.apana.org.au (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show

Commit Message

Herbert Xu May 7, 2018, 5:14 p.m. UTC
This patch changes the parsing of here-documents within command
substitution, both old style and new style.  In particular, the
original here-document list is saved upon the beginning of parsing
command substitution and restored when exiting.

This means that here-documents outside of command substitution
can no longer be filled by text within it and vice-versa.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
diff mbox

Patch

diff --git a/src/parser.c b/src/parser.c
index 8e40781..1c56c83 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1363,6 +1363,7 @@  parsebackq: {
 	union node *n;
 	char *str;
 	size_t savelen;
+	struct heredoc *saveheredoclist;
 	int uninitialized_var(saveprompt);
 
 	str = NULL;
@@ -1427,6 +1428,9 @@  done:
 	*nlpp = (struct nodelist *)stalloc(sizeof (struct nodelist));
 	(*nlpp)->next = NULL;
 
+	saveheredoclist = heredoclist;
+	heredoclist = NULL;
+
 	if (oldstyle) {
 		saveprompt = doprompt;
 		doprompt = 0;
@@ -1439,17 +1443,18 @@  done:
 	else {
 		if (readtoken() != TRP)
 			synexpect(TRP);
+		setinputstring(nullstr);
+		parseheredoc();
 	}
 
+	heredoclist = saveheredoclist;
+
 	(*nlpp)->n = n;
-        if (oldstyle) {
-		/*
-		 * Start reading from old file again, ignoring any pushed back
-		 * tokens left from the backquote parsing
-		 */
-                popfile();
+	/* Start reading from old file again. */
+	popfile();
+	/* Ignore any pushed back tokens left from the backquote parsing. */
+	if (oldstyle)
 		tokpushback = 0;
-	}
 	while (stackblocksize() <= savelen)
 		growstackblock();
 	STARTSTACKSTR(out);