diff options
author | Ron Yorston <rmy@pobox.com> | 2019-04-18 09:49:13 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-04-19 13:21:34 +0200 |
commit | d1a2fa2a4e013960bf56dfef8a71ed2d08fc756b (patch) | |
tree | 6d47b357fbc99a10fa026b969b8e53200b69681e | |
parent | 48645b83502a5add5429b6cbb19cf3a083f1adf4 (diff) | |
download | busybox-w32-d1a2fa2a4e013960bf56dfef8a71ed2d08fc756b.tar.gz busybox-w32-d1a2fa2a4e013960bf56dfef8a71ed2d08fc756b.tar.bz2 busybox-w32-d1a2fa2a4e013960bf56dfef8a71ed2d08fc756b.zip |
ash: catch error in arithmetic expansion in PS1
Setting PS1 to:
PS1='$((123+))'
causes the shell to enter an infinite error loop:
sh: arithmetic syntax error
Catch any exception raised by expandarg() in expandstr() and allow
processing to continue.
function old new delta
expandstr 262 344 +82
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 82/0) Total: 82 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/shell/ash.c b/shell/ash.c index f3a2c6952..924e17f32 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -13043,6 +13043,9 @@ expandstr(const char *ps, int syntax_type) | |||
13043 | union node n; | 13043 | union node n; |
13044 | int saveprompt; | 13044 | int saveprompt; |
13045 | struct parsefile *file_stop = g_parsefile; | 13045 | struct parsefile *file_stop = g_parsefile; |
13046 | volatile int saveint; | ||
13047 | struct jmploc *volatile savehandler = exception_handler; | ||
13048 | struct jmploc jmploc; | ||
13046 | 13049 | ||
13047 | /* XXX Fix (char *) cast. */ | 13050 | /* XXX Fix (char *) cast. */ |
13048 | setinputstring((char *)ps); | 13051 | setinputstring((char *)ps); |
@@ -13054,18 +13057,13 @@ expandstr(const char *ps, int syntax_type) | |||
13054 | * Try a prompt with syntactically wrong command: | 13057 | * Try a prompt with syntactically wrong command: |
13055 | * PS1='$(date "+%H:%M:%S) > ' | 13058 | * PS1='$(date "+%H:%M:%S) > ' |
13056 | */ | 13059 | */ |
13057 | { | 13060 | SAVE_INT(saveint); |
13058 | volatile int saveint; | 13061 | if (setjmp(jmploc.loc) == 0) { |
13059 | struct jmploc *volatile savehandler = exception_handler; | 13062 | exception_handler = &jmploc; |
13060 | struct jmploc jmploc; | 13063 | readtoken1(pgetc(), syntax_type, FAKEEOFMARK, 0); |
13061 | SAVE_INT(saveint); | ||
13062 | if (setjmp(jmploc.loc) == 0) { | ||
13063 | exception_handler = &jmploc; | ||
13064 | readtoken1(pgetc(), syntax_type, FAKEEOFMARK, 0); | ||
13065 | } | ||
13066 | exception_handler = savehandler; | ||
13067 | RESTORE_INT(saveint); | ||
13068 | } | 13064 | } |
13065 | exception_handler = savehandler; | ||
13066 | RESTORE_INT(saveint); | ||
13069 | 13067 | ||
13070 | doprompt = saveprompt; | 13068 | doprompt = saveprompt; |
13071 | 13069 | ||
@@ -13077,7 +13075,17 @@ expandstr(const char *ps, int syntax_type) | |||
13077 | n.narg.text = wordtext; | 13075 | n.narg.text = wordtext; |
13078 | n.narg.backquote = backquotelist; | 13076 | n.narg.backquote = backquotelist; |
13079 | 13077 | ||
13080 | expandarg(&n, NULL, EXP_QUOTED); | 13078 | /* expandarg() might fail too: |
13079 | * PS1='$((123+))' | ||
13080 | */ | ||
13081 | SAVE_INT(saveint); | ||
13082 | if (setjmp(jmploc.loc) == 0) { | ||
13083 | exception_handler = &jmploc; | ||
13084 | expandarg(&n, NULL, EXP_QUOTED); | ||
13085 | } | ||
13086 | exception_handler = savehandler; | ||
13087 | RESTORE_INT(saveint); | ||
13088 | |||
13081 | return stackblock(); | 13089 | return stackblock(); |
13082 | } | 13090 | } |
13083 | 13091 | ||