diff options
author | David Mitchell <davem@iabyn.com> | 2015-09-21 14:49:22 +0100 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2015-10-02 11:29:35 +0100 |
commit | 052a7c766b9640ee847979cb9d2351a63e23a378 (patch) | |
tree | 1a796b916aa4702854196a5c6ef9767b4d6b98e8 /lib | |
parent | 6768377c79109b7124f0c8a4e3677982689d9f49 (diff) | |
download | perl-052a7c766b9640ee847979cb9d2351a63e23a378.tar.gz |
fix up EXTEND() callers
The previous commit made it clear that the N argument to EXTEND()
is supposed to be signed, in particular SSize_t, and now typically
triggers compiler warnings where this isn't the case.
This commit fixes the various places in core that passed the wrong sort of
N to EXTEND(). The fixes are in three broad categories.
First, where sensible, I've changed the relevant var to be SSize_t.
Second, where its expected that N could never be large enough to wrap,
I've just added an assert and a cast.
Finally, I've added extra code to detect whether the cast could
wrap/truncate, and if so set N to -1, which will trigger a panic in
stack_grow().
This also fixes
[perl #125937] 'x' operator on list causes segfault with possible
stack corruption
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ExtUtils/typemap | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/ExtUtils/typemap b/lib/ExtUtils/typemap index 5f61527dea..1cdb8465f6 100644 --- a/lib/ExtUtils/typemap +++ b/lib/ExtUtils/typemap @@ -378,7 +378,11 @@ T_PACKEDARRAY T_ARRAY { U32 ix_$var; - EXTEND(SP,size_$var); + SSize_t extend_size = + sizeof(size_$var) > sizeof(SSize_t) && size_$var > SSize_t_MAX + ? -1 /* might wrap; -1 triggers a panic in EXTEND() */ + : (SSize_t)size_$var; + EXTEND(SP, extend_size); for (ix_$var = 0; ix_$var < size_$var; ix_$var++) { ST(ix_$var) = sv_newmortal(); DO_ARRAY_ELEM |