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>
This commit is contained in:
parent
48645b8350
commit
d1a2fa2a4e
18
shell/ash.c
18
shell/ash.c
@ -13043,6 +13043,9 @@ expandstr(const char *ps, int syntax_type)
|
|||||||
union node n;
|
union node n;
|
||||||
int saveprompt;
|
int saveprompt;
|
||||||
struct parsefile *file_stop = g_parsefile;
|
struct parsefile *file_stop = g_parsefile;
|
||||||
|
volatile int saveint;
|
||||||
|
struct jmploc *volatile savehandler = exception_handler;
|
||||||
|
struct jmploc jmploc;
|
||||||
|
|
||||||
/* XXX Fix (char *) cast. */
|
/* XXX Fix (char *) cast. */
|
||||||
setinputstring((char *)ps);
|
setinputstring((char *)ps);
|
||||||
@ -13054,10 +13057,6 @@ expandstr(const char *ps, int syntax_type)
|
|||||||
* Try a prompt with syntactically wrong command:
|
* Try a prompt with syntactically wrong command:
|
||||||
* PS1='$(date "+%H:%M:%S) > '
|
* PS1='$(date "+%H:%M:%S) > '
|
||||||
*/
|
*/
|
||||||
{
|
|
||||||
volatile int saveint;
|
|
||||||
struct jmploc *volatile savehandler = exception_handler;
|
|
||||||
struct jmploc jmploc;
|
|
||||||
SAVE_INT(saveint);
|
SAVE_INT(saveint);
|
||||||
if (setjmp(jmploc.loc) == 0) {
|
if (setjmp(jmploc.loc) == 0) {
|
||||||
exception_handler = &jmploc;
|
exception_handler = &jmploc;
|
||||||
@ -13065,7 +13064,6 @@ expandstr(const char *ps, int syntax_type)
|
|||||||
}
|
}
|
||||||
exception_handler = savehandler;
|
exception_handler = savehandler;
|
||||||
RESTORE_INT(saveint);
|
RESTORE_INT(saveint);
|
||||||
}
|
|
||||||
|
|
||||||
doprompt = saveprompt;
|
doprompt = saveprompt;
|
||||||
|
|
||||||
@ -13077,7 +13075,17 @@ expandstr(const char *ps, int syntax_type)
|
|||||||
n.narg.text = wordtext;
|
n.narg.text = wordtext;
|
||||||
n.narg.backquote = backquotelist;
|
n.narg.backquote = backquotelist;
|
||||||
|
|
||||||
|
/* expandarg() might fail too:
|
||||||
|
* PS1='$((123+))'
|
||||||
|
*/
|
||||||
|
SAVE_INT(saveint);
|
||||||
|
if (setjmp(jmploc.loc) == 0) {
|
||||||
|
exception_handler = &jmploc;
|
||||||
expandarg(&n, NULL, EXP_QUOTED);
|
expandarg(&n, NULL, EXP_QUOTED);
|
||||||
|
}
|
||||||
|
exception_handler = savehandler;
|
||||||
|
RESTORE_INT(saveint);
|
||||||
|
|
||||||
return stackblock();
|
return stackblock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user