This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
smartmatch: handle stack realloc
authorDavid Mitchell <davem@iabyn.com>
Wed, 18 Mar 2015 17:06:49 +0000 (17:06 +0000)
committerDavid Mitchell <davem@iabyn.com>
Thu, 19 Mar 2015 14:51:52 +0000 (14:51 +0000)
commite8fe1b7c7ff6b3263ab2423a9a3f63ad85ea3aff
tree1d98c05604dce7807f0d0cb607376ec06c4f18a3
parent72e5fb6312b534c67eb2da0525dd3c09b5f9222b
smartmatch: handle stack realloc

When smartmatch is matching a pattern against something, it was
failing to do appropriate PUTBACK and SPAGAIN's  before calling
matcher_matches_sv() (which pushes an arg an calls pp_match()).
If the stack was almost full, the extra push in matcher_matches_sv()
could cause a stack realloc, which would then be ignored when
pp_smartmatch() returned, setting PL_stack_sp to point to the old (freed)
stack.

Adding SPAGAIN ensures that PL_stack_sp points to the new stack, while
PUTBACK causes PL_stack_sp to no longer see the two args to pp_smartmatch,
so the PUSH in matcher_matches_sv() pushes the SV us9ng ones of two two
reclaimed slots, so the stack won't re-alloc anyway.

Thus by doing the "right thing" with both PUTBACK and SPAGAIN, we
doubly ensure that PL_stack_sp will always be right.
pp_ctl.c
t/op/smartmatch.t