From: Herbert Xu <herbert@gondor.apana.org.au>
To: Harald van Dijk <harald@gigawatt.nl>
Cc: Ron Yorston <rmy@frippery.org>,
contact@emersion.fr, dash@vger.kernel.org
Subject: [PATCH] parser: Save and restore heredoclist in expandstr
Date: Sun, 17 May 2020 23:36:25 +1000 [thread overview]
Message-ID: <20200517133625.GA15227@gondor.apana.org.au> (raw)
In-Reply-To: <15d522d8-e0f5-be2a-f2a2-8b17290fce31@gigawatt.nl>
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 --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;
}
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
prev parent reply other threads:[~2020-05-17 13:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <SJhI_AW9YJmphaap5RzzVqYTGsA529iV7GOEBafT9ilDPGFpMRRJlNt3TrMBwh0uqKQltSvsH2P8x_2in6enHT5DzygjAtrRSvWl5xHofeY=@emersion.fr>
2020-01-21 6:39 ` [PATCH] parser: Catch errors in expandstr Herbert Xu
2020-01-21 17:06 ` Simon Ser
2020-02-26 21:12 ` Ron Yorston
2020-02-28 0:40 ` Herbert Xu
2020-04-28 6:17 ` [v2 PATCH] " Herbert Xu
2020-05-17 12:19 ` Harald van Dijk
2020-05-17 13:36 ` Herbert Xu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200517133625.GA15227@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=contact@emersion.fr \
--cc=dash@vger.kernel.org \
--cc=harald@gigawatt.nl \
--cc=rmy@frippery.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).