WordPress.org

Make WordPress Core

Ticket #19571: 19571.diff

File 19571.diff, 1.3 KB (added by mdawaffe, 6 years ago)

oops - forgot to attach the file :)

  • wp-includes/pluggable.php

     
    15051505endif;
    15061506
    15071507if ( !function_exists('wp_rand') ) :
    1508  /**
     1508/**
    15091509 * Generates a random number
    15101510 *
    15111511 * @since 2.6.2
    15121512 *
    1513  * @param int $min Lower limit for the generated number (optional, default is 0)
    1514  * @param int $max Upper limit for the generated number (optional, default is 4294967295)
     1513 * @param int $min Lower limit for the generated number
     1514 * @param int $max Upper limit for the generated number
    15151515 * @return int A random number between min and max
    15161516 */
    15171517function wp_rand( $min = 0, $max = 0 ) {
     
    15401540
    15411541        $value = abs(hexdec($value));
    15421542
     1543        // Some misconfigured 32bit environments (Etropy PHP, for example) truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
     1544        $max_random_number = 3000000000 === 2147483647 ? (float) "4294967295" : 4294967295; // 4294967295 = 0xffffffff
     1545
    15431546        // Reduce the value to be within the min - max range
    1544         // 4294967295 = 0xffffffff = max random number
    15451547        if ( $max != 0 )
    1546                 $value = $min + (($max - $min + 1) * ($value / (4294967295 + 1)));
     1548                $value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 );
    15471549
    15481550        return abs(intval($value));
    15491551}