Make WordPress Core


Ignore:
Timestamp:
03/08/2016 05:14:52 PM (9 years ago)
Author:
ocean90
Message:

Update Random_Compat from 1.1.6 to 1.2.1.

Changes: https://github.com/paragonie/random_compat/compare/1.1.6...v1.2.1

See #35665.

File:
1 edited

Legend:

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

    r36421 r36886  
    11<?php
    22/**
    3  * Random_* Compatibility Library 
     3 * Random_* Compatibility Library
    44 * for using the new PHP 7 random_* API in PHP 5 projects
    5  *
     5 *
     6 * @version 1.2.1
     7 * @released 2016-02-29
     8 *
    69 * The MIT License (MIT)
    7  * 
     10 *
    811 * Copyright (c) 2015 Paragon Initiative Enterprises
    9  * 
     12 *
    1013 * Permission is hereby granted, free of charge, to any person obtaining a copy
    1114 * of this software and associated documentation files (the "Software"), to deal
     
    1417 * copies of the Software, and to permit persons to whom the Software is
    1518 * furnished to do so, subject to the following conditions:
    16  * 
     19 *
    1720 * The above copyright notice and this permission notice shall be included in
    1821 * all copies or substantial portions of the Software.
    19  * 
     22 *
    2023 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    2124 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     
    3033    // This constant was introduced in PHP 5.2.7
    3134    $RandomCompatversion = explode('.', PHP_VERSION);
    32     define('PHP_VERSION_ID', ($RandomCompatversion[0] * 10000 + $RandomCompatversion[1] * 100 + $RandomCompatversion[2]));
     35    define(
     36        'PHP_VERSION_ID',
     37        $RandomCompatversion[0] * 10000
     38        + $RandomCompatversion[1] * 100
     39        + $RandomCompatversion[2]
     40    );
    3341    $RandomCompatversion = null;
    3442}
     43
    3544if (PHP_VERSION_ID < 70000) {
     45
    3646    if (!defined('RANDOM_COMPAT_READ_BUFFER')) {
    3747        define('RANDOM_COMPAT_READ_BUFFER', 8);
    3848    }
     49
    3950    $RandomCompatDIR = dirname(__FILE__);
     51
    4052    require_once $RandomCompatDIR.'/byte_safe_strings.php';
    4153    require_once $RandomCompatDIR.'/cast_to_int.php';
    4254    require_once $RandomCompatDIR.'/error_polyfill.php';
     55
    4356    if (!function_exists('random_bytes')) {
    4457        /**
    4558         * PHP 5.2.0 - 5.6.x way to implement random_bytes()
    46          * 
     59         *
    4760         * We use conditional statements here to define the function in accordance
    4861         * to the operating environment. It's a micro-optimization.
    49          * 
     62         *
    5063         * In order of preference:
    5164         *   1. Use libsodium if available.
     
    5467         *   4. COM('CAPICOM.Utilities.1')->GetRandom()
    5568         *   5. openssl_random_pseudo_bytes() (absolute last resort)
    56          * 
     69         *
    5770         * See ERRATA.md for our reasoning behind this particular order
    5871         */
     
    6578            }
    6679        }
     80
    6781        /**
    6882         * Reading directly from /dev/urandom:
     
    7387            $RandomCompatUrandom = true;
    7488            $RandomCompat_basedir = ini_get('open_basedir');
     89
    7590            if (!empty($RandomCompat_basedir)) {
    7691                $RandomCompat_open_basedir = explode(
     
    8499                $RandomCompat_open_basedir = null;
    85100            }
     101
    86102            if (
    87                 !function_exists('random_bytes') &&
    88                 $RandomCompatUrandom &&
     103                !function_exists('random_bytes')
     104                &&
     105                $RandomCompatUrandom
     106                &&
    89107                @is_readable('/dev/urandom')
    90108            ) {
    91109                // Error suppression on is_readable() in case of an open_basedir
    92110                // 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 
     111                // can read it at this point. If the PHP environment is going to
     112                // panic over trying to see if the file can be read in the first
    95113                // place, that is not helpful to us here.
    96114
     
    99117            }
    100118            // Unset variables after use
     119            $RandomCompat_basedir = null;
    101120            $RandomCompatUrandom = null;
    102             $RandomCompat_basedir = null;
    103         }
    104        
     121        }
     122
    105123        /**
    106124         * mcrypt_create_iv()
    107125         */
    108126        if (
    109             !function_exists('random_bytes') &&
    110             PHP_VERSION_ID >= 50307 &&
     127            !function_exists('random_bytes')
     128            &&
     129            PHP_VERSION_ID >= 50307
     130            &&
    111131            extension_loaded('mcrypt')
    112132        ) {
    113             // See random_bytes_mcrypt.php
    114             require_once $RandomCompatDIR.'/random_bytes_mcrypt.php';
    115         }
     133            // Prevent this code from hanging indefinitely on non-Windows;
     134            // see https://bugs.php.net/bug.php?id=69833
     135            if (
     136                DIRECTORY_SEPARATOR !== '/' ||
     137                (PHP_VERSION_ID <= 50609 || PHP_VERSION_ID >= 50613)
     138            ) {
     139                // See random_bytes_mcrypt.php
     140                require_once $RandomCompatDIR.'/random_bytes_mcrypt.php';
     141            }
     142        }
     143
    116144        if (
    117             !function_exists('random_bytes') &&
    118             extension_loaded('com_dotnet') &&
     145            !function_exists('random_bytes')
     146            &&
     147            extension_loaded('com_dotnet')
     148            &&
    119149            class_exists('COM')
    120150        ) {
    121151            $RandomCompat_disabled_classes = preg_split(
    122                 '#\s*,\s*#', 
     152                '#\s*,\s*#',
    123153                strtolower(ini_get('disable_classes'))
    124154            );
    125            
     155
    126156            if (!in_array('com', $RandomCompat_disabled_classes)) {
    127157                try {
     
    138168            $RandomCompatCOMtest = null;
    139169        }
    140        
     170
    141171        /**
    142172         * openssl_random_pseudo_bytes()
    143173         */
    144174        if (
    145             !function_exists('random_bytes') &&
    146             extension_loaded('openssl') &&
    147175            (
    148176                // Unix-like with PHP >= 5.3.0 or
    149177                (
    150                     DIRECTORY_SEPARATOR === '/' &&
     178                    DIRECTORY_SEPARATOR === '/'
     179                    &&
    151180                    PHP_VERSION_ID >= 50300
    152                 ) ||
     181                )
     182                ||
    153183                // Windows with PHP >= 5.4.1
    154184                PHP_VERSION_ID >= 50401
    155185            )
     186            &&
     187            !function_exists('random_bytes')
     188            &&
     189            extension_loaded('openssl')
    156190        ) {
    157191            // See random_bytes_openssl.php
    158192            require_once $RandomCompatDIR.'/random_bytes_openssl.php';
    159193        }
    160        
     194
    161195        /**
    162196         * throw new Exception
     
    175209        }
    176210    }
     211
    177212    if (!function_exists('random_int')) {
    178213        require_once $RandomCompatDIR.'/random_int.php';
    179214    }
     215
    180216    $RandomCompatDIR = null;
    181217}
Note: See TracChangeset for help on using the changeset viewer.