ash: survive failures in $PS1 expansion. Closes 10371
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 12 Oct 2017 17:20:13 +0000 (19:20 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 12 Oct 2017 17:20:13 +0000 (19:20 +0200)
function                                             old     new   delta
expandstr                                            120     209     +89

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash.c

index 39705a350aba14b95ab06b8c783bd5443a2586f2..ef81ea70f6fa27347f490c2ea8679edb8e94c1db 100644 (file)
@@ -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();