aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2018-05-19 02:39:42 +0800
committerBen Hutchings <ben@decadent.org.uk>2020-03-28 21:42:55 +0000
commitf7bb177a0dbd9750f78988a3636fa3c32418f6d7 (patch)
treeb389404e54efd2613afcf6a4ec73b0bfa10ca89a
parent93ae53d4cde3d461f987804e9bb3f2291c59c30f (diff)
downloadklibc-f7bb177a0dbd9750f78988a3636fa3c32418f6d7.tar.gz
[klibc] dash: parser: Save/restore here-documents in command substitution
[ dash commit 51e2d88d6e513150a76c007111bbee21bb922c33 ] 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> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r--usr/dash/parser.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/usr/dash/parser.c b/usr/dash/parser.c
index 8bd3db44ff3d0..809c6a8a96d29 100644
--- a/usr/dash/parser.c
+++ b/usr/dash/parser.c
@@ -1368,6 +1368,7 @@ parsebackq: {
union node *n;
char *str;
size_t savelen;
+ struct heredoc *saveheredoclist;
int uninitialized_var(saveprompt);
str = NULL;
@@ -1432,6 +1433,9 @@ done:
*nlpp = (struct nodelist *)stalloc(sizeof (struct nodelist));
(*nlpp)->next = NULL;
+ saveheredoclist = heredoclist;
+ heredoclist = NULL;
+
if (oldstyle) {
saveprompt = doprompt;
doprompt = 0;
@@ -1444,17 +1448,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);