From a8f4d2ebc900d9b9048e92accc58c2713d64c98a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be> Date: Mon, 2 Jul 2018 09:35:18 +0200 Subject: [PATCH] :ambulance: fix(core) Fix 2 problems in random_int fallback Throw Exception when max is less than min Unpack with Q instead of C to support ranges wider than 255 issue #5843 --- include/functions.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/functions.inc b/include/functions.inc index 37e51681a..8ec8ea645 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -2468,7 +2468,7 @@ if (!function_exists('random_int')) { { $range = $max - $min; if ($range <= 0) { - return $min; + throw new Exception('Invalid range passed to random_int'); } $log = log($range, 2); @@ -2483,7 +2483,7 @@ if (!function_exists('random_int')) { if (!$strong || ($randomBytes === FALSE)) { throw new Exception('Failed to get random bytes'); } - $rnd = unpack('C', $randomBytes)[1]; + $rnd = unpack('Q', $randomBytes)[1]; // discard irrelevant bits $rnd = $rnd & $filter; } while ($rnd >= $range); -- GitLab