Make WordPress Core

Changeset 36421


Ignore:
Timestamp:
01/30/2016 12:56:07 AM (9 years ago)
Author:
dd32
Message:

Update Random_Compat to the latest version (1.1.6).

See #35665

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/random_compat/random.php

    r36220 r36421  
    5151         *   1. Use libsodium if available.
    5252         *   2. fread() /dev/urandom if available (never on Windows)
    53          *   3. mcrypt_create_iv($bytes, MCRYPT_CREATE_IV)
     53         *   3. mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM)
    5454         *   4. COM('CAPICOM.Utilities.1')->GetRandom()
    5555         *   5. openssl_random_pseudo_bytes() (absolute last resort)
     
    6565            }
    6666        }
    67         if (
    68             !function_exists('random_bytes') &&
    69             DIRECTORY_SEPARATOR === '/' &&
    70             @is_readable('/dev/urandom')
    71         ) {
     67        /**
     68         * Reading directly from /dev/urandom:
     69         */
     70        if (DIRECTORY_SEPARATOR === '/') {
    7271            // DIRECTORY_SEPARATOR === '/' on Unix-like OSes -- this is a fast
    7372            // way to exclude Windows.
    74             //
    75             // Error suppression on is_readable() in case of an open_basedir or
    76             // safe_mode failure. All we care about is whether or not we can
    77             // read it at this point. If the PHP environment is going to panic
    78             // over trying to see if the file can be read in the first place,
    79             // that is not helpful to us here.
    80            
    81             // See random_bytes_dev_urandom.php
     73            $RandomCompatUrandom = true;
     74            $RandomCompat_basedir = ini_get('open_basedir');
     75            if (!empty($RandomCompat_basedir)) {
     76                $RandomCompat_open_basedir = explode(
     77                    PATH_SEPARATOR,
     78                    strtolower($RandomCompat_basedir)
     79                );
     80                $RandomCompatUrandom = in_array(
     81                    '/dev',
     82                    $RandomCompat_open_basedir
     83                );
     84                $RandomCompat_open_basedir = null;
     85            }
     86            if (
     87                !function_exists('random_bytes') &&
     88                $RandomCompatUrandom &&
     89                @is_readable('/dev/urandom')
     90            ) {
     91                // Error suppression on is_readable() in case of an open_basedir
     92                // or safe_mode failure. All we care about is whether or not we
     93                // can read it at this point. If the PHP environment is going to
     94                // panic over trying to see if the file can be read in the first
     95                // place, that is not helpful to us here.
     96
     97                // See random_bytes_dev_urandom.php
    8298                require_once $RandomCompatDIR.'/random_bytes_dev_urandom.php';
    8399            }
     100            // Unset variables after use
     101            $RandomCompatUrandom = null;
     102            $RandomCompat_basedir = null;
     103        }
     104       
     105        /**
     106         * mcrypt_create_iv()
     107         */
    84108        if (
    85109            !function_exists('random_bytes') &&
     
    114138            $RandomCompatCOMtest = null;
    115139        }
     140       
     141        /**
     142         * openssl_random_pseudo_bytes()
     143         */
    116144        if (
    117145            !function_exists('random_bytes') &&
     
    130158            require_once $RandomCompatDIR.'/random_bytes_openssl.php';
    131159        }
     160       
     161        /**
     162         * throw new Exception
     163         */
    132164        if (!function_exists('random_bytes')) {
    133165            /**
     
    135167             * and hope the developer won't let it fail silently.
    136168             */
    137             function random_bytes()
     169            function random_bytes($length)
    138170            {
    139171                throw new Exception(
Note: See TracChangeset for help on using the changeset viewer.