Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash while handling subshell trap (rhbz#1117404)
Contrary to the RH bug report, this is yet another bug with virtual/non-forked subshells and has nothing to do with functions. If a signal is ignored (empty trap) in the main shell while any trap (empty or not) is set on the same signal in a subshell, a crash eventually occurred upon restoring state when leaving the subshell. Original patch: https://src.fedoraproject.org/rpms/ksh/blob/642af4d6/f/ksh-20120801-trapcom.patch Prior discussion: https://bugzilla.redhat.com/1117404 Paulo Andrade wrote there: > The problem is that the sh_subshell function was saving pointers > that could change, and when restoring, bad things would happen. [...] > The only comment I added: > /* contents of shp->st.trapcom may change */ > may be a bit misleading, the "bad" save/restore already knows it, > probably I should have added a better description telling that the > data is, usually, modified in code like: > > tmp = buf[i]; buf[i] = strdup(tmp); free(tmp); > > so the shp->st.trapcom needs a "deep copy", as done in the > patch, to properly save/restore pointers. src/cmd/ksh93/sh/subshell.c, src/cmd/ksh93/sh/xec.c: - sh_subshell(), sh_funscope(): Make *savsig/*savstak into a **savsig array. Use strdup(3) to save the data and get known pointers that will not change. Free these upon restore. - Change the comment from the patch as Paulo wished he had done. src/cmd/ksh93/tests/subshell.sh: - Test 2500 times. This should trigger the crash most of the time.
- Loading branch information
Showing
3 changed files
with
64 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters