mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
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
This commit is contained in:
parent
ba43436f10
commit
b0a6c1bde5
3 changed files with 82 additions and 27 deletions
4
NEWS
4
NEWS
|
@ -8,10 +8,8 @@ Any uppercase BUG_* names are modernish shell bug IDs.
|
|||
- Fixed a bug in emacs mode: after using tab completion to complete the name
|
||||
of a directory, it was not possible to type numbers after the slash.
|
||||
|
||||
2021-04-15:
|
||||
|
||||
- Fixed an optimization bug that caused the <>; redirection operator to fail
|
||||
when used in -c scripts.
|
||||
when used with the last command in a -c script.
|
||||
|
||||
2021-04-14:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue