diff options
author | Ron Yorston <rmy@pobox.com> | 2019-04-18 09:48:13 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-04-19 13:21:34 +0200 |
commit | 48645b83502a5add5429b6cbb19cf3a083f1adf4 (patch) | |
tree | 87a59484fb86b2589de1b3f14b0d102c2d7f8a38 | |
parent | 32c8ce4def177a98a9aef0896bdb2d8262b364ec (diff) | |
download | busybox-w32-48645b83502a5add5429b6cbb19cf3a083f1adf4.tar.gz busybox-w32-48645b83502a5add5429b6cbb19cf3a083f1adf4.tar.bz2 busybox-w32-48645b83502a5add5429b6cbb19cf3a083f1adf4.zip |
ash: prevent error in backquotes in PS1 from exiting shell
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>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/shell/ash.c b/shell/ash.c index b707d00d0..f3a2c6952 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -13042,6 +13042,7 @@ expandstr(const char *ps, int syntax_type) | |||
13042 | { | 13042 | { |
13043 | union node n; | 13043 | union node n; |
13044 | int saveprompt; | 13044 | int saveprompt; |
13045 | struct parsefile *file_stop = g_parsefile; | ||
13045 | 13046 | ||
13046 | /* XXX Fix (char *) cast. */ | 13047 | /* XXX Fix (char *) cast. */ |
13047 | setinputstring((char *)ps); | 13048 | setinputstring((char *)ps); |
@@ -13068,7 +13069,8 @@ expandstr(const char *ps, int syntax_type) | |||
13068 | 13069 | ||
13069 | doprompt = saveprompt; | 13070 | doprompt = saveprompt; |
13070 | 13071 | ||
13071 | popfile(); | 13072 | /* Try: PS1='`xxx(`' */ |
13073 | unwindfiles(file_stop); | ||
13072 | 13074 | ||
13073 | n.narg.type = NARG; | 13075 | n.narg.type = NARG; |
13074 | n.narg.next = NULL; | 13076 | n.narg.next = NULL; |