aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorGravatar Ron Yorston <rmy@pobox.com>2019-04-18 09:49:13 +0100
committerGravatar Denys Vlasenko <vda.linux@googlemail.com>2019-04-19 13:21:34 +0200
commitd1a2fa2a4e013960bf56dfef8a71ed2d08fc756b (patch)
tree6d47b357fbc99a10fa026b969b8e53200b69681e /shell
parent48645b83502a5add5429b6cbb19cf3a083f1adf4 (diff)
downloadbusybox-d1a2fa2a4e013960bf56dfef8a71ed2d08fc756b.tar.gz
busybox-d1a2fa2a4e013960bf56dfef8a71ed2d08fc756b.tar.bz2
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>
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c32
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)
union node n;
int saveprompt;
struct parsefile *file_stop = g_parsefile;
+ volatile int saveint;
+ struct jmploc *volatile savehandler = exception_handler;
+ struct jmploc jmploc;
/* XXX Fix (char *) cast. */
setinputstring((char *)ps);
@@ -13054,18 +13057,13 @@ expandstr(const char *ps, int syntax_type)
* Try a prompt with syntactically wrong command:
* PS1='$(date "+%H:%M:%S) > '
*/
- {
- volatile int saveint;
- struct jmploc *volatile savehandler = exception_handler;
- struct jmploc jmploc;
- SAVE_INT(saveint);
- if (setjmp(jmploc.loc) == 0) {
- exception_handler = &jmploc;
- readtoken1(pgetc(), syntax_type, FAKEEOFMARK, 0);
- }
- exception_handler = savehandler;
- RESTORE_INT(saveint);
+ SAVE_INT(saveint);
+ if (setjmp(jmploc.loc) == 0) {
+ exception_handler = &jmploc;
+ readtoken1(pgetc(), syntax_type, FAKEEOFMARK, 0);
}
+ exception_handler = savehandler;
+ RESTORE_INT(saveint);
doprompt = saveprompt;
@@ -13077,7 +13075,17 @@ expandstr(const char *ps, int syntax_type)
n.narg.text = wordtext;
n.narg.backquote = backquotelist;
- expandarg(&n, NULL, EXP_QUOTED);
+ /* expandarg() might fail too:
+ * PS1='$((123+))'
+ */
+ SAVE_INT(saveint);
+ if (setjmp(jmploc.loc) == 0) {
+ exception_handler = &jmploc;
+ expandarg(&n, NULL, EXP_QUOTED);
+ }
+ exception_handler = savehandler;
+ RESTORE_INT(saveint);
+
return stackblock();
}