aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-10-12 19:20:13 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-10-12 19:20:13 +0200
commita2e32b324eb7440f0cd4992f54f7a5822c145e91 (patch)
tree7b36bca131ac4f8f2f535f9b8b66dcb0c7860cf7
parent0fd5dbba8f34e006aa0e999002d31e79daf2fdf3 (diff)
downloadbusybox-a2e32b324eb7440f0cd4992f54f7a5822c145e91.tar.gz
ash: survive failures in $PS1 expansion. Closes 10371
function old new delta expandstr 120 209 +89 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 39705a350..ef81ea70f 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -12656,7 +12656,24 @@ expandstr(const char *ps, int syntax_type)
saveprompt = doprompt;
doprompt = 0;
- readtoken1(pgetc(), syntax_type, FAKEEOFMARK, 0);
+
+ /* readtoken1() might die horribly.
+ * Try a prompt with syntacticallyt 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);
+ }
+
doprompt = saveprompt;
popfile();