From d4be40cd41e70e291f7a52836675d54e4c6e0142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Wed, 31 Mar 2021 09:39:32 +0200 Subject: [PATCH] Fix an arithmetic left shift of a minimal integer value --- ...ft-shift-of-IV_MIN-under-use-integer.patch | 62 +++++++++++++++++++ perl.spec | 7 +++ 2 files changed, 69 insertions(+) create mode 100644 perl-5.33.8-Fix-broken-left-shift-of-IV_MIN-under-use-integer.patch diff --git a/perl-5.33.8-Fix-broken-left-shift-of-IV_MIN-under-use-integer.patch b/perl-5.33.8-Fix-broken-left-shift-of-IV_MIN-under-use-integer.patch new file mode 100644 index 0000000..5ce6046 --- /dev/null +++ b/perl-5.33.8-Fix-broken-left-shift-of-IV_MIN-under-use-integer.patch @@ -0,0 +1,62 @@ +From 4e82c85b1c9c9b30253b8624470da6f20a6c0604 Mon Sep 17 00:00:00 2001 +From: Karl Williamson +Date: Mon, 15 Mar 2021 21:01:47 -0600 +Subject: [PATCH] Fix broken left shift of IV_MIN under 'use integer' +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This fixes GH 18639 + +When I wrote this code, I conflated casting and complementing. + +Signed-off-by: Petr Písař +--- + pp.c | 3 --- + t/op/bop.t | 9 ++++++++- + 2 files changed, 8 insertions(+), 4 deletions(-) + +diff --git a/pp.c b/pp.c +index d365afea4c..baf0777a47 100644 +--- a/pp.c ++++ b/pp.c +@@ -2007,9 +2007,6 @@ static IV S_iv_shift(IV iv, int shift, bool left) + * 18446744073709551552 + * */ + if (left) { +- if (iv == IV_MIN) { /* Casting this to a UV is undefined behavior */ +- return 0; +- } + return (IV) (((UV) iv) << shift); + } + +diff --git a/t/op/bop.t b/t/op/bop.t +index 07f057d0a9..31b6531a03 100644 +--- a/t/op/bop.t ++++ b/t/op/bop.t +@@ -18,7 +18,7 @@ BEGIN { + # If you find tests are failing, please try adding names to tests to track + # down where the failure is, and supply your new names as a patch. + # (Just-in-time test naming) +-plan tests => 502; ++plan tests => 503; + + # numerics + ok ((0xdead & 0xbeef) == 0x9ead); +@@ -33,6 +33,13 @@ ok ((33023 >> 7) == 257); + # signed vs. unsigned + ok ((~0 > 0 && do { use integer; ~0 } == -1)); + ++{ # GH #18639 ++ my $iv_min = -(~0 >> 1) - 1; ++ my $shifted; ++ { use integer; $shifted = $iv_min << 0 }; ++ is($shifted, $iv_min, "IV_MIN << 0 yields IV_MIN under 'use integer'"); ++} ++ + my $bits = 0; + for (my $i = ~0; $i; $i >>= 1) { ++$bits; } + my $cusp = 1 << ($bits - 1); +-- +2.26.3 + diff --git a/perl.spec b/perl.spec index 4da4f26..9ddb993 100644 --- a/perl.spec +++ b/perl.spec @@ -276,6 +276,10 @@ Patch56: perl-5.33.7-regcomp.c-Remove-memory-leak.patch # Fix dumping a hash entry of PL_strtab type, in upstream after 5.33.7 Patch57: perl-5.32.1-Perl_do_sv_dump-handle-PL_strtab.patch +# Fix an arithmetic left shift of a minimal integer value, GH#18639, +# in upstream after 5.33.8 +Patch58: perl-5.33.8-Fix-broken-left-shift-of-IV_MIN-under-use-integer.patch + # Link XS modules to libperl.so with EU::CBuilder on Linux, bug #960048 Patch200: perl-5.16.3-Link-XS-modules-to-libperl.so-with-EU-CBuilder-on-Li.patch @@ -4334,6 +4338,7 @@ you're not running VMS, this module does nothing. %patch55 -p1 %patch56 -p1 %patch57 -p1 +%patch58 -p1 %patch200 -p1 %patch201 -p1 @@ -4390,6 +4395,7 @@ perl -x patchlevel.h \ 'Fedora Patch55: Prevent the number of buckets in a hash from getting too large' \ 'Fedora Patch56: Fix a memory leak when compiling a regular expression (GH#18604)' \ 'Fedora Patch57: Fix dumping a hash entry of PL_strtab type' \ + 'Fedora Patch57: Fix an arithmetic left shift of a minimal integer value (GH#18639)' \ 'Fedora Patch200: Link XS modules to libperl.so with EU::CBuilder on Linux' \ 'Fedora Patch201: Link XS modules to libperl.so with EU::MM on Linux' \ %{nil} @@ -7166,6 +7172,7 @@ popd %changelog * Wed Mar 31 2021 Petr Pisar - 4:5.32.1-474 - Fix dumping a hash entry of PL_strtab type +- Fix an arithmetic left shift of a minimal integer value (GH#18639) * Thu Mar 04 2021 Jitka Plesnikova - 4:5.32.1-473 - Remove files excluded from dual-lived subpackages