HomeFreeBSD

MFC r314686: sh: Fix crash if a -T trap is taken during command substitution.

Description

MFC r314686: sh: Fix crash if a -T trap is taken during command substitution.

Code like t=$(stat -f %m "$file") segfaulted if -T was active and a trap
was taken while the shell was waiting for the child process to finish.

What happened was that the dotrap() call in waitforjob() was hit. This
re-entered command execution (including expand.c) at a point not expected by
expbackq(), and global state (unallocated stack string and argbackq) was
corrupted.

To fix this, change expbackq() to prepare for command execution to be
re-entered.

In stable/10, there is more global state that needs to be restored than in
stable/11 and head.

Reported by: bdrewery

Details

Provenance
jillesAuthored on
Parents
rS316941: Don't try to write out bufs that have already failed with ENXIO.
Branches
Unknown
Tags
Unknown