You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Perl_repeatcpy() arg 4 bug is not reachable from PP from my limited test, through 1 of 2 libperl funcs that use Perl_repeatcpy(). I didn't try func 2. Fact check and verify this yourself, but all callers, 2 func, 3 call sites total, are doing their own bounds checking, which makes the bound checking attempts in Perl_repeatcpy() pointless or inappropriate API design or inappropriate delegation and abstraction of responsibilities.
5.41.7 Win64
C:\sources\perl5>perl -E" sub mks { return 'a' x 0xFFFFFFFFFFFFFFFF} print(mks()
);" > t3.txt
Out of memory in perl:util:safesysrealloc
panic: fold_constants JMPENV_PUSH returned 2 at -e line 1.
Free to wrong pool 4303b8 not 4275c0 at (null) line 1 during global destruction.
strawberry `uname='Win32 strawberry-perl 5.32.1.1 #1 Sun Jan 24 12:17:47 2021 i386'
C:\sources>perl -E" sub mks { return 'a' x 0x80000000} print(mks());" > t3.txt
Out of memory!
panic: fold_constants JMPENV_PUSH returned 2 at -e line 1.
Free to wrong pool 6cc780 not 6cc7b0 at (null) line 1 during global destruction.
got SEGV popup on windows ^^^
C:\sources>perl -E" sub mks { return 'abcdefgh' x 0x80000000} print(mks());" > t
3.txt
Out of memory during string extend at -e line 1.
C:\sources>perl -E" sub mks { return 'abcdefgh' x 0x8000000} print(mks());" > t3
.txt
Out of memory!
C:\sources>perl -E" sub mks { return @{$_[0]} x 0x100000000;} foreach(mks(['a'])
) {print $_};" > t3.txt
Out of memory during string extend at -e line 1.
C:\sources>perl -E" sub mks { return (@{$_[0]}) x 0x100000000;} foreach(mks(['a'
])) {print $_};" > t3.txt
Out of memory during list extend at -e line 1.
Expected behavior
Use Size_t type for arg 4 on all builds configs, the way it should've been written from day 1.
I don't have any opinion or proposal on how to correctly fix arg 4. Many questions:
but statement if (i64_count < 0) croak_memory_wrap(); is useless on a 32b CPU.
Which call frame/context does the 64b IV -> 32b size_t cast or truncate and bounds check logic? 64b IVs/int64_t on 32b CPUs is always emulated by the C compiler using multiple instructions 4 byte/32bit CPU ops.
Make a PvREPEATCPY() macro to do the bounds check and truncate in the caller?
Perl_repeatcpy is marked as public API, now what? What is the policy on breaking DarkPAN?
NOTE: 2 callers in libperl, 0 hits on grepcpan. Someone else should repeat my search attempts.
Deprecate, mathom, "no warning" delete the function by renaming to Perl_repeatcpy2 or Perl_repeatcpyn, etc?
Keep overflow hazard broken version as a libperl export under current name, Perl_repeatcpy and make a non exported Perl_repeatcpy_p for PERL_CORE?
I was happy to find Perl_repeatcpy exists in libperl's toolkit and had a thought of maybe using it myself in a future perl FOSS patch, vs DIYing it the traditional way with for(;;i++) {size_t[i] = size_t[i];}, but that plan changed after reading Perl_repeatcpy's src code.
Description
Most related commits that I found:
26e1303 don't segfault given string repeat count larger than 2^31
2709980 avoid calling memset with a negative count
https://nvd.nist.gov/vuln/detail/CVE-2012-5195
Steps to Reproduce
Perl_repeatcpy() arg 4 bug is not reachable from PP from my limited test, through 1 of 2 libperl funcs that use Perl_repeatcpy(). I didn't try func 2. Fact check and verify this yourself, but all callers, 2 func, 3 call sites total, are doing their own bounds checking, which makes the bound checking attempts in
Perl_repeatcpy()
pointless or inappropriate API design or inappropriate delegation and abstraction of responsibilities.5.41.7 Win64
strawberry `uname='Win32 strawberry-perl 5.32.1.1 #1 Sun Jan 24 12:17:47 2021 i386'
got SEGV popup on windows ^^^
Expected behavior
Use
Size_t
type for arg 4 on all builds configs, the way it should've been written from day 1.I don't have any opinion or proposal on how to correctly fix arg 4. Many questions:
but statement
if (i64_count < 0) croak_memory_wrap();
is useless on a 32b CPU.Which call frame/context does the 64b IV -> 32b size_t cast or truncate and bounds check logic? 64b IVs/
int64_t
on 32b CPUs is always emulated by the C compiler using multiple instructions 4 byte/32bit CPU ops.Make a
PvREPEATCPY()
macro to do the bounds check and truncate in the caller?Perl_repeatcpy is marked as public API, now what? What is the policy on breaking DarkPAN?
NOTE: 2 callers in
libperl
, 0 hits on grepcpan. Someone else should repeat my search attempts.Deprecate, mathom, "no warning" delete the function by renaming to
Perl_repeatcpy2
orPerl_repeatcpyn
, etc?Keep overflow hazard broken version as a libperl export under current name,
Perl_repeatcpy
and make a non exportedPerl_repeatcpy_p
for PERL_CORE?I was happy to find
Perl_repeatcpy
exists in libperl's toolkit and had a thought of maybe using it myself in a future perl FOSS patch, vs DIYing it the traditional way withfor(;;i++) {size_t[i] = size_t[i];}
, but that plan changed after readingPerl_repeatcpy
's src code.Perl configuration
The text was updated successfully, but these errors were encountered: