1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00
cde/src/cmd/ksh93/sh
Martijn Dekker b0a6c1bde5 Further fix '<>;' and fix crash on 32-bit systems (re: 6701bb30)
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
2021-04-17 21:56:39 +01:00
..
args.c Fix handling of '--posix' and '--default' (#265) 2021-04-09 23:26:07 +01:00
arith.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
array.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
defs.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
deparse.c Fix various minor problems and update the documentation (#237) 2021-03-21 14:39:03 +00:00
expand.c Add --globcasedetect shell option for globbing and completion 2021-03-22 18:45:19 +00:00
fault.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
fcin.c Fix many GCC -Wimplicit-fallthrough warnings (#243) 2021-03-30 21:49:20 +01:00
init.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
io.c Backport bugfix for BUG_CSUBSTDO from ksh93v- 2012-08-24 (#259) 2021-04-08 13:24:17 +01:00
jobs.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
lex.c lex.c: simplify fmttoken() by using the stack (re: 3255aed2) 2021-04-09 17:36:29 +01:00
macro.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
main.c Fix <>; redirection for final command exec optimization (#277) 2021-04-15 18:29:50 +01:00
name.c Correct memory fault when removing default nameref KSH_VERSION (#271) 2021-04-13 03:15:34 +01:00
nvdisc.c nv_disc(NV_LAST) loses trailing shell context from discipline stack (#276) 2021-04-15 14:41:32 +01:00
nvtree.c Fix various minor problems and update the documentation (#237) 2021-03-21 14:39:03 +00:00
nvtype.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
parse.c Allow invoking path-bound built-in commands by direct path or preceding PATH assignment (#275) 2021-04-15 04:08:12 +01:00
path.c Allow invoking path-bound built-in commands by direct path or preceding PATH assignment (#275) 2021-04-15 04:08:12 +01:00
pmain.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
shcomp.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
streval.c Reset arithmetic recursion level on all errors (re: 264ba48b) 2021-04-11 01:25:19 +01:00
string.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
subshell.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
suid_exec.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
tdump.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
timers.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
trestore.c '#if 0' cleanup 2020-08-30 04:51:20 +01:00
waitevent.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
xec.c Further fix '<>;' and fix crash on 32-bit systems (re: 6701bb30) 2021-04-17 21:56:39 +01:00