[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH 1/2] ash: prevent error in backquotes in PS1 from exiting shell
From:       Ron Yorston <rmy () pobox ! com>
Date:       2019-04-18 8:48:13
Message-ID: 5cb839cd.FE7ol0UgGizidEyh%rmy () pobox ! com
[Download RAW message or body]

Setting PS1 to:

   PS1='`xxx(`'

causes the shell to terminate with the error:

   sh: syntax error: unexpected end of file (expecting ")")

This happens because old-style backquotes require the input to be reread
and thus call setinputstring() a second time.  Prevent the problem by
unwinding all recently opened files in expandstr().

function                                             old     new   delta
unwindfiles                                            -      22     +22
expandstr                                            247     262     +15
forkchild                                            631     625      -6
evalcommand                                         1694    1685      -9
ash_main                                            1346    1336     -10
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/3 up/down: 37/-25)             Total: 12 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
---
 shell/ash.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/shell/ash.c b/shell/ash.c
index b707d00d0..039524010 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -13042,6 +13042,7 @@ expandstr(const char *ps, int syntax_type)
 {
 	union node n;
 	int saveprompt;
+	struct parsefile *file_stop = g_parsefile;
 
 	/* XXX Fix (char *) cast. */
 	setinputstring((char *)ps);
@@ -13068,7 +13069,7 @@ expandstr(const char *ps, int syntax_type)
 
 	doprompt = saveprompt;
 
-	popfile();
+	unwindfiles(file_stop);
 
 	n.narg.type = NARG;
 	n.narg.next = NULL;
-- 
2.20.1

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic