aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-02-17 12:11:26 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-02-17 12:11:26 +0100
commit74aaf05170d6f224194c98ee0434e2decae45735 (patch)
treec228795cc7ccfcf7cfab18c054ef7bc8e9d775d8
parentafc91faeddd6b8234dccea2f7913f57a5bb3d1ec (diff)
downloadbusybox-w32-74aaf05170d6f224194c98ee0434e2decae45735.tar.gz
busybox-w32-74aaf05170d6f224194c98ee0434e2decae45735.tar.bz2
busybox-w32-74aaf05170d6f224194c98ee0434e2decae45735.zip
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>
-rw-r--r--shell/ash.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/shell/ash.c b/shell/ash.c
index fbe8dd9e4..e0ddf7198 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -12733,6 +12733,7 @@ parsebackq: {
12733 union node *n; 12733 union node *n;
12734 char *str; 12734 char *str;
12735 size_t savelen; 12735 size_t savelen;
12736 struct heredoc *saveheredoclist;
12736 smallint saveprompt = 0; 12737 smallint saveprompt = 0;
12737 12738
12738 str = NULL; 12739 str = NULL;
@@ -12808,6 +12809,9 @@ parsebackq: {
12808 *nlpp = stzalloc(sizeof(**nlpp)); 12809 *nlpp = stzalloc(sizeof(**nlpp));
12809 /* (*nlpp)->next = NULL; - stzalloc did it */ 12810 /* (*nlpp)->next = NULL; - stzalloc did it */
12810 12811
12812 saveheredoclist = heredoclist;
12813 heredoclist = NULL;
12814
12811 if (oldstyle) { 12815 if (oldstyle) {
12812 saveprompt = doprompt; 12816 saveprompt = doprompt;
12813 doprompt = 0; 12817 doprompt = 0;
@@ -12817,18 +12821,21 @@ parsebackq: {
12817 12821
12818 if (oldstyle) 12822 if (oldstyle)
12819 doprompt = saveprompt; 12823 doprompt = saveprompt;
12820 else if (readtoken() != TRP) 12824 else {
12821 raise_error_unexpected_syntax(TRP); 12825 if (readtoken() != TRP)
12826 raise_error_unexpected_syntax(TRP);
12827 setinputstring(nullstr);
12828 parseheredoc();
12829 }
12830
12831 heredoclist = saveheredoclist;
12822 12832
12823 (*nlpp)->n = n; 12833 (*nlpp)->n = n;
12824 if (oldstyle) { 12834 /* Start reading from old file again. */
12825 /* 12835 popfile();
12826 * Start reading from old file again, ignoring any pushed back 12836 /* Ignore any pushed back tokens left from the backquote parsing. */
12827 * tokens left from the backquote parsing 12837 if (oldstyle)
12828 */
12829 popfile();
12830 tokpushback = 0; 12838 tokpushback = 0;
12831 }
12832 while (stackblocksize() <= savelen) 12839 while (stackblocksize() <= savelen)
12833 growstackblock(); 12840 growstackblock();
12834 STARTSTACKSTR(out); 12841 STARTSTACKSTR(out);