mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Accessing t->tre.treio for every sh_exec() run is invalid because 't' is of type Shnode_t, which is a union that can contain many different kinds of structs. As all members of a union occupy the same address space, only one can be used at a time. Which member is valid to access depends on the node type sh_exec() was called with. The invalid access triggered a crash on 32-bit systems when executing an arithmetic command like ((x=1)). The t->tre.treio union member should be accessed for a simple command (case TCOM in sh_exec()). The fix is also needed for redirections attached to blocks (case TSETIO) in which case the union member to use is t->fork.forkio. src/cmd/ksh93/sh/xec.c: - Add check_exec_optimization() function that checks for all the conditions where the exec optimisation should not be done. For redirections we need to loop through the whole list to check for an IOREWRITE (<>;) one. - sh_exec(): case TCOM (simple command): Only bother to call check_exec_optimization() if there are either command arguments or redirections (IOW: don't bother for bare variable assignments), so move it to within the if(io||argn) block. - sh_exec(): case TSETIO: This needs a similar fix. To avoid the optimization breaking again if the last command is a subshell with a <>; redirection attached, we need to not only set execflg to 0 but also clear the SH_NOFORK state bit from the 'flags' variable which is passed on to the recursive sh_exec() call. src/cmd/ksh93/tests/io.sh: - Update and expand tests. Add tests for redirections attached to simple commands (TCOM) and various kinds of code block (TSETIO). Co-authored-by: Johnothan King <johnothanking@protonmail.com> Resolves: https://github.com/ksh93/ksh/issues/278 |
||
|---|---|---|
| .. | ||
| args.c | ||
| arith.c | ||
| array.c | ||
| defs.c | ||
| deparse.c | ||
| expand.c | ||
| fault.c | ||
| fcin.c | ||
| init.c | ||
| io.c | ||
| jobs.c | ||
| lex.c | ||
| macro.c | ||
| main.c | ||
| name.c | ||
| nvdisc.c | ||
| nvtree.c | ||
| nvtype.c | ||
| parse.c | ||
| path.c | ||
| pmain.c | ||
| shcomp.c | ||
| streval.c | ||
| string.c | ||
| subshell.c | ||
| suid_exec.c | ||
| tdump.c | ||
| timers.c | ||
| trestore.c | ||
| waitevent.c | ||
| xec.c | ||