In signal handler, don't inc stack pointers
authorDavid Mitchell <davem@iabyn.com>
Sat, 19 Mar 2011 21:29:16 +0000 (21:29 +0000)
committerDavid Mitchell <davem@iabyn.com>
Sat, 19 Mar 2011 22:03:40 +0000 (22:03 +0000)
commit9a7f166c9e80e6dce5b942cb7af5fc213e0466d4
treec614aac028847948e8ea2e13cef9c3ee4df49727
parent55fa63f5f326538bec794ff6b165abff1ea07579
In signal handler, don't inc stack pointers

In Perl_sighandler, we currently increment PL_markstack_ptr and
PL_scopestack_ix.

This was added back in 1997 in the era of unsafe signals, to make them
slightly less unsafe. The idea presumably was to stop signal handlers
inadvertently corrupting the top element of each stack. However, given that
the normal method of pushing something onto those stacks is to increment
the pointer before pushing the value, I don't see how that can happen.

The downside of this is that an uninitialised or stale value can be left
in the 'hole' left on these stacks. When exiting from a signal handler via
exit(), these holes can be read and corruption occur, while stack
unwinding is taking place. The ordering of things means we can't use
SAVEDESTRUCTOR_X to undo the damage.

This commit leaves the 'PL_savestack_ix += 5', because in this case, with
unsafe signals, it *is* possible to interrupt halfway through a new set of
save data being pushed onto the stack, and it *is* possible for this to be
undone via SAVEDESTRUCTOR_X. (But it's still unsafe and half-baked.)

This fixes [perl #85206].
mg.c