[klibc] [klibc:update-dash] input: Fix here-document redirection with vi/emacs on

klibc-bot for Harald van Dijk harald at gigawatt.nl
Thu Jan 24 19:15:47 PST 2019

Commit-ID:  1c21d74d9383d4ca0c9fb07c522fbf3b377d8b3c
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=1c21d74d9383d4ca0c9fb07c522fbf3b377d8b3c
Author:     Harald van Dijk <harald at gigawatt.nl>
AuthorDate: Fri, 30 Jun 2017 01:33:29 +0200
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Fri, 25 Jan 2019 02:57:21 +0000

[klibc] input: Fix here-document redirection with vi/emacs on

On 27/06/17 16:29, Zando Fardones wrote:
> Hello,
> I think I've found a bug when using the here-document redirection in
> an interactive shell. What basically happens is that you can't see the
> command output if you set the "vi" or "emacs" options.

That's not quite what happens: the here-document contents got lost, so
there is no command output to see. Nice find.

The problem is that getprompt() is implicitly called by el_gets(). This
messes with the memory used by the parser to store the here-document's
contents. In the non-emacs/vi case, the prompt is explicitly written by
setprompt(), which wraps the getprompt() call in a
pushstackmark()/popstackmark() pair to restore the state so that parsing
can continue. But when getprompt() is called by el_gets(), it knows
nothing about this.

The whole call to el_gets() can be surrounded by another
pushstackmark()/popstackmark() pair to solve the problem, as attached.

Harald van Dijk

Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

 usr/dash/input.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/usr/dash/input.c b/usr/dash/input.c
index 06c08d49..e53423c5 100644
--- a/usr/dash/input.c
+++ b/usr/dash/input.c
@@ -147,8 +147,12 @@ retry:
 		static const char *rl_cp;
 		static int el_len;
-		if (rl_cp == NULL)
+		if (rl_cp == NULL) {
+			struct stackmark smark;
+			pushstackmark(&smark, stackblocksize());
 			rl_cp = el_gets(el, &el_len);
+			popstackmark(&smark);
+		}
 		if (rl_cp == NULL)
 			nr = 0;
 		else {

More information about the klibc mailing list