Commit a8f4d2eb authored by Côme Chilliet's avatar Côme Chilliet
Browse files

: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
Showing with 2 additions and 2 deletions
+2 -2
......@@ -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');
  • :warning: Define and throw a dedicated exception instead of using a generic one. :blue_book:

    By Ghost User on 2018-07-02T07:40:10 (imported from GitLab)

Please register or sign in to reply
}
$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);
......
  • SonarQube analysis reported 1 issue

    • :warning: 1 major

    Watch the comments in this conversation to review them.

    By Ghost User on 2018-07-02T07:40:11 (imported from GitLab)

  • bmortier @bmortier

    mentioned in commit 6009d96f

    By Côme Chilliet on 2018-07-02T07:46:45 (imported from GitLab)

    ·

    mentioned in commit 6009d96f

    By Côme Chilliet on 2018-07-02T07:46:45 (imported from GitLab)

    Toggle commit list
  • bmortier @bmortier

    mentioned in merge request !320

    By Côme Chilliet on 2018-07-02T07:47:01 (imported from GitLab)

    ·

    mentioned in merge request !320

    By Côme Chilliet on 2018-07-02T07:47:01 (imported from GitLab)

    Toggle commit list
  • bmortier @bmortier

    mentioned in commit 0c7d2c1e

    By Côme Chilliet on 2018-07-02T07:48:17 (imported from GitLab)

    ·

    mentioned in commit 0c7d2c1e

    By Côme Chilliet on 2018-07-02T07:48:17 (imported from GitLab)

    Toggle commit list
  • bmortier @bmortier

    mentioned in merge request !321

    By Côme Chilliet on 2018-07-02T07:48:30 (imported from GitLab)

    ·

    mentioned in merge request !321

    By Côme Chilliet on 2018-07-02T07:48:30 (imported from GitLab)

    Toggle commit list
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment