This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
ss_dup: make new savestack have SS_MAXPUSH extra
authorDavid Mitchell <davem@iabyn.com>
Tue, 5 Apr 2016 08:26:21 +0000 (09:26 +0100)
committerDavid Mitchell <davem@iabyn.com>
Tue, 5 Apr 2016 08:26:21 +0000 (09:26 +0100)
This fixes RT #perl #127799

My commit v5.23.7-261-g3caf026 made PL_savestack_max claim to have
allocated less than had actually been claimed (by a margin of SS_MAXPUSH).
This made the 'check whether the stack needs extending code' slightly
simpler, and errs on the side of safety. Except:

Perl_ss_dup(), when duplicating the savestack, makes the new stack
PL_savestack_max in size, which is large enough to duplicate the existing
stack, but the new stack no longer has a SS_MAXPUSH margin at the top.

The dSS_ADD family of macros work by assuming there is always such a
margin: they push their args onto the stack and only then check whether
the stack needs growing. This makes the code much more efficient, but of
course breaks if no margin is present.

sv.c

diff --git a/sv.c b/sv.c
index 819a250..0200679 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -14182,7 +14182,7 @@ Perl_ss_dup(pTHX_ PerlInterpreter *proto_perl, CLONE_PARAMS* param)
 {
     dVAR;
     ANY * const ss     = proto_perl->Isavestack;
-    const I32 max      = proto_perl->Isavestack_max;
+    const I32 max      = proto_perl->Isavestack_max + SS_MAXPUSH;
     I32 ix             = proto_perl->Isavestack_ix;
     ANY *nss;
     const SV *sv;