summaryrefslogtreecommitdiff
path: root/cpan/Scalar-List-Utils
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2016-02-29 08:39:02 -0500
committerJarkko Hietaniemi <jhi@iki.fi>2016-02-29 20:44:20 -0500
commitd962874bb2fb8159ec2e9f58745d6d02b56e84c7 (patch)
tree749b6d80a29c4364e699c6e22d8787a24c2de913 /cpan/Scalar-List-Utils
parent98e2bb74e9450c612d85b3f54540f899f9e3a7ea (diff)
downloadperl-d962874bb2fb8159ec2e9f58745d6d02b56e84c7.tar.gz
product() with zero IV crash/hang
CID 104785: Division or modulo by zero (DIVIDE_BY_ZERO) 238. divide_by_zero: In expression 9223372036854775807L / retiv, division by expression retiv which may be zero has undefined behavior. 215 if(!SvNOK(sv) && SvIOK(sv) && (SvIV(sv) < IV_MAX / retiv)) { Cherry-pick of the changes in https://rt.cpan.org/Public/Bug/Display.html?id=105415
Diffstat (limited to 'cpan/Scalar-List-Utils')
-rw-r--r--cpan/Scalar-List-Utils/ListUtil.xs3
-rw-r--r--cpan/Scalar-List-Utils/t/product.t5
2 files changed, 6 insertions, 2 deletions
diff --git a/cpan/Scalar-List-Utils/ListUtil.xs b/cpan/Scalar-List-Utils/ListUtil.xs
index 504c70e8b1..04dca10eba 100644
--- a/cpan/Scalar-List-Utils/ListUtil.xs
+++ b/cpan/Scalar-List-Utils/ListUtil.xs
@@ -212,7 +212,8 @@ CODE:
break;
case ACC_IV:
if(is_product) {
- if(!SvNOK(sv) && SvIOK(sv) && (SvIV(sv) < IV_MAX / retiv)) {
+ if(retiv == 0 ||
+ (!SvNOK(sv) && SvIOK(sv) && (SvIV(sv) < IV_MAX / retiv))) {
retiv *= SvIV(sv);
break;
}
diff --git a/cpan/Scalar-List-Utils/t/product.t b/cpan/Scalar-List-Utils/t/product.t
index c397f828c6..38c923be50 100644
--- a/cpan/Scalar-List-Utils/t/product.t
+++ b/cpan/Scalar-List-Utils/t/product.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 13;
+use Test::More tests => 14;
use List::Util qw(product);
@@ -19,6 +19,9 @@ is( $v, 24, '4 args');
$v = product(-1);
is( $v, -1, 'one -1');
+$v = product(0, 1, 2);
+is( $v, 0, 'first factor zero' );
+
my $x = -3;
$v = product($x, 3);