summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko2020-02-17 12:11:26 +0100
committerDenys Vlasenko2020-02-17 12:11:26 +0100
commit74aaf05170d6f224194c98ee0434e2decae45735 (patch)
treec228795cc7ccfcf7cfab18c054ef7bc8e9d775d8 /shell
parentafc91faeddd6b8234dccea2f7913f57a5bb3d1ec (diff)
downloadbusybox-74aaf05170d6f224194c98ee0434e2decae45735.zip
busybox-74aaf05170d6f224194c98ee0434e2decae45735.tar.gz
ash: parser: Save/restore here-documents in command substitution
Upstream comment: Date: Sat, 19 May 2018 02:39:42 +0800 parser: Save/restore here-documents in command substitution 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: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/shell/ash.c b/shell/ash.c
index fbe8dd9..e0ddf71 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -12733,6 +12733,7 @@ parsebackq: {
union node *n;
char *str;
size_t savelen;
+ struct heredoc *saveheredoclist;
smallint saveprompt = 0;
str = NULL;
@@ -12808,6 +12809,9 @@ parsebackq: {
*nlpp = stzalloc(sizeof(**nlpp));
/* (*nlpp)->next = NULL; - stzalloc did it */
+ saveheredoclist = heredoclist;
+ heredoclist = NULL;
+
if (oldstyle) {
saveprompt = doprompt;
doprompt = 0;
@@ -12817,18 +12821,21 @@ parsebackq: {
if (oldstyle)
doprompt = saveprompt;
- else if (readtoken() != TRP)
- raise_error_unexpected_syntax(TRP);
+ else {
+ if (readtoken() != TRP)
+ raise_error_unexpected_syntax(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);