mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix crash in xtrace while processing here-document (re: d7cada7b)
Depending on the OS, the heredoc.sh regression tests, and possibly others, still crashed with the -x option (xtrace) on. Analysis: The lexer crashes in lex_advance(). Something has caused an inconsistent lexer state, and it happened earlier on, so the backtrace is useless for figuring out where that happened. But I think I've found it. It's the sh_mactry() call here: src/cmd/ksh93/sh/xec.c, lines 2800 to 2807 inf7213f032800: if(!(cp=nv_getval(sh_scoped(shp,PS4NOD)))) 2801: cp = "+ "; 2802: else 2803: { 2804: sh_offoption(SH_XTRACE); 2805: cp = sh_mactry(shp,cp); 2806: sh_onoption(SH_XTRACE); 2807: } sh_mactry() needs to parse the contents of $PS4 to perform expansions and command substitutions in it, which involves the lexer. If that happens in a here-document, the lexer is in the C function call stack, in the middle of parsing the here-document. Result: inconsistent lexer state. Solution: save and restore lexer state in sh_mactry(). After this commit, all regression tests should pass with the '-x'/'--xtrace' option in use, with no errors or crashes. Note for backporters: this fix depends both on ond7cada7band on the consistency fix for the Lex_t type's size applied in a7ed5d9f. src/cmd/ksh93/include/shlex.h: - Cosmetic fix: remove a copied & pasted backslash. (re: a7ed5d9f) src/cmd/ksh93/sh/macro.c: sh_mactry(): - Save and restore the lexer state before letting sh_mactrim() indirectly parse and execute code. src/cmd/ksh93/tests/*.sh: - Turn off xtrace in various command substitutions that contain 2>&1 redirections, so that the xtrace output is not caught by the command substitutions, causing tests to fail incorrectly. - Turn off xtrace for a few code blocks with 2>&1 redirections, stopping xtrace output from being written to standard output. Resolves: https://github.com/ksh93/ksh/issues/306 (again)
This commit is contained in:
parent
91a7c2e3e9
commit
e072e7c170
10 changed files with 28 additions and 16 deletions
|
|
@ -124,6 +124,7 @@ void *sh_macopen(Shell_t *shp)
|
|||
|
||||
/*
|
||||
* perform only parameter substitution and catch failures
|
||||
* (also save lexer state to allow use while in here-docs)
|
||||
*/
|
||||
char *sh_mactry(Shell_t *shp,register char *string)
|
||||
{
|
||||
|
|
@ -132,11 +133,13 @@ char *sh_mactry(Shell_t *shp,register char *string)
|
|||
int jmp_val;
|
||||
int savexit = shp->savexit;
|
||||
struct checkpt buff;
|
||||
Lex_t *lexp = (Lex_t*)sh.lex_context, savelex = *lexp;
|
||||
sh_pushcontext(shp,&buff,SH_JMPSUB);
|
||||
jmp_val = sigsetjmp(buff.buff,0);
|
||||
if(jmp_val == 0)
|
||||
string = sh_mactrim(shp,string,0);
|
||||
sh_popcontext(shp,&buff);
|
||||
*lexp = savelex;
|
||||
shp->savexit = savexit;
|
||||
return(string);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue