Changeset 36421
- Timestamp:
- 01/30/2016 12:56:07 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/random_compat/random.php
r36220 r36421 51 51 * 1. Use libsodium if available. 52 52 * 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) 54 54 * 4. COM('CAPICOM.Utilities.1')->GetRandom() 55 55 * 5. openssl_random_pseudo_bytes() (absolute last resort) … … 65 65 } 66 66 } 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 === '/') { 72 71 // DIRECTORY_SEPARATOR === '/' on Unix-like OSes -- this is a fast 73 72 // 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 82 98 require_once $RandomCompatDIR.'/random_bytes_dev_urandom.php'; 83 99 } 100 // Unset variables after use 101 $RandomCompatUrandom = null; 102 $RandomCompat_basedir = null; 103 } 104 105 /** 106 * mcrypt_create_iv() 107 */ 84 108 if ( 85 109 !function_exists('random_bytes') && … … 114 138 $RandomCompatCOMtest = null; 115 139 } 140 141 /** 142 * openssl_random_pseudo_bytes() 143 */ 116 144 if ( 117 145 !function_exists('random_bytes') && … … 130 158 require_once $RandomCompatDIR.'/random_bytes_openssl.php'; 131 159 } 160 161 /** 162 * throw new Exception 163 */ 132 164 if (!function_exists('random_bytes')) { 133 165 /** … … 135 167 * and hope the developer won't let it fail silently. 136 168 */ 137 function random_bytes( )169 function random_bytes($length) 138 170 { 139 171 throw new Exception(
Note: See TracChangeset
for help on using the changeset viewer.