diff mbox series

parser: Save and restore heredoclist in expandstr

Message ID 20200517133625.GA15227@gondor.apana.org.au (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series parser: Save and restore heredoclist in expandstr | expand

Commit Message

Herbert Xu May 17, 2020, 1:36 p.m. UTC
On Sun, May 17, 2020 at 01:19:28PM +0100, Harald van Dijk wrote:
>
> This still does not restore the state completely. It does not clean up any
> pending heredocs. I see:
> 
>   $ PS1='$(<<EOF "'
>   src/dash: 1: Syntax error: Unterminated quoted string
>   $(<<EOF ":
>   >
> 
> That is, after entering the ':' command, the shell is still trying to read
> the heredoc from the prompt.

This patch saves and restores the heredoclist in expandstr.

It also removes a bunch of unnecessary volatiles as those variables
are only referenced in case of a longjmp other than one started by
a signal like SIGINT.

Reported-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
diff mbox series

Patch

diff --git a/src/parser.c b/src/parser.c
index 3131045..54c2861 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1565,10 +1565,11 @@  setprompt(int which)
 const char *
 expandstr(const char *ps)
 {
-	struct parsefile *volatile file_stop;
+	struct parsefile *file_stop;
 	struct jmploc *volatile savehandler;
-	const char *volatile result;
-	volatile int saveprompt;
+	struct heredoc *saveheredoclist;
+	const char *result;
+	int saveprompt;
 	struct jmploc jmploc;
 	union node n;
 	int err;
@@ -1578,6 +1579,8 @@  expandstr(const char *ps)
 	/* XXX Fix (char *) cast. */
 	setinputstring((char *)ps);
 
+	saveheredoclist = heredoclist;
+	heredoclist = NULL;
 	saveprompt = doprompt;
 	doprompt = 0;
 	result = ps;
@@ -1603,6 +1606,7 @@  out:
 
 	doprompt = saveprompt;
 	unwindfiles(file_stop);
+	heredoclist = saveheredoclist;
 
 	return result;
 }