From 1fdfabf74cf652dfeaa51eb57933d89f762cf9fa Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Fri, 1 Dec 2017 03:07:42 +0000 Subject: [PATCH] Avoid PHP Linting errors in the Random_Compat library under PHP7. The latest updates to the library are larger than preferred, so instead this modifies the library to lint properly. Fixes #42439 for 4.9 Built from https://develop.svn.wordpress.org/branches/4.9@42344 git-svn-id: http://core.svn.wordpress.org/branches/4.9@42173 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/random_compat/random_bytes_com_dotnet.php | 2 ++ wp-includes/random_compat/random_bytes_dev_urandom.php | 2 ++ wp-includes/random_compat/random_bytes_libsodium.php | 2 ++ wp-includes/random_compat/random_bytes_libsodium_legacy.php | 2 ++ wp-includes/random_compat/random_bytes_mcrypt.php | 2 ++ wp-includes/random_compat/random_bytes_openssl.php | 2 ++ wp-includes/random_compat/random_int.php | 2 ++ 7 files changed, 14 insertions(+) diff --git a/wp-includes/random_compat/random_bytes_com_dotnet.php b/wp-includes/random_compat/random_bytes_com_dotnet.php index 3422825492..b42da1674c 100644 --- a/wp-includes/random_compat/random_bytes_com_dotnet.php +++ b/wp-includes/random_compat/random_bytes_com_dotnet.php @@ -26,6 +26,7 @@ * SOFTWARE. */ +if ( ! is_callable( 'random_bytes' ) ): /** * Windows with PHP < 5.3.0 will not have the function * openssl_random_pseudo_bytes() available, so let's use @@ -79,3 +80,4 @@ function random_bytes($bytes) 'Could not gather sufficient random data' ); } +endif; diff --git a/wp-includes/random_compat/random_bytes_dev_urandom.php b/wp-includes/random_compat/random_bytes_dev_urandom.php index db93b07578..8700bfead0 100644 --- a/wp-includes/random_compat/random_bytes_dev_urandom.php +++ b/wp-includes/random_compat/random_bytes_dev_urandom.php @@ -30,6 +30,7 @@ if (!defined('RANDOM_COMPAT_READ_BUFFER')) { define('RANDOM_COMPAT_READ_BUFFER', 8); } +if ( ! is_callable( 'random_bytes' ) ): /** * Unless open_basedir is enabled, use /dev/urandom for * random numbers in accordance with best practices @@ -146,3 +147,4 @@ function random_bytes($bytes) 'Error reading from source device' ); } +endif; diff --git a/wp-includes/random_compat/random_bytes_libsodium.php b/wp-includes/random_compat/random_bytes_libsodium.php index f802d4e124..5b24fcf173 100644 --- a/wp-includes/random_compat/random_bytes_libsodium.php +++ b/wp-includes/random_compat/random_bytes_libsodium.php @@ -26,6 +26,7 @@ * SOFTWARE. */ +if ( ! is_callable( 'random_bytes' ) ): /** * If the libsodium PHP extension is loaded, we'll use it above any other * solution. @@ -84,3 +85,4 @@ function random_bytes($bytes) 'Could not gather sufficient random data' ); } +endif; diff --git a/wp-includes/random_compat/random_bytes_libsodium_legacy.php b/wp-includes/random_compat/random_bytes_libsodium_legacy.php index 44fddbf6fc..bf4d5ef58b 100644 --- a/wp-includes/random_compat/random_bytes_libsodium_legacy.php +++ b/wp-includes/random_compat/random_bytes_libsodium_legacy.php @@ -26,6 +26,7 @@ * SOFTWARE. */ +if ( ! is_callable( 'random_bytes' ) ): /** * If the libsodium PHP extension is loaded, we'll use it above any other * solution. @@ -84,3 +85,4 @@ function random_bytes($bytes) 'Could not gather sufficient random data' ); } +endif; diff --git a/wp-includes/random_compat/random_bytes_mcrypt.php b/wp-includes/random_compat/random_bytes_mcrypt.php index 7ac9d9105f..f8b100a9f3 100644 --- a/wp-includes/random_compat/random_bytes_mcrypt.php +++ b/wp-includes/random_compat/random_bytes_mcrypt.php @@ -27,6 +27,7 @@ */ +if ( ! is_callable( 'random_bytes' ) ): /** * Powered by ext/mcrypt (and thankfully NOT libmcrypt) * @@ -74,3 +75,4 @@ function random_bytes($bytes) 'Could not gather sufficient random data' ); } +endif; diff --git a/wp-includes/random_compat/random_bytes_openssl.php b/wp-includes/random_compat/random_bytes_openssl.php index 62bf770352..619dae9abb 100644 --- a/wp-includes/random_compat/random_bytes_openssl.php +++ b/wp-includes/random_compat/random_bytes_openssl.php @@ -26,6 +26,7 @@ * SOFTWARE. */ +if ( ! is_callable( 'random_bytes' ) ): /** * Since openssl_random_pseudo_bytes() uses openssl's * RAND_pseudo_bytes() API, which has been marked as deprecated by the @@ -81,3 +82,4 @@ function random_bytes($bytes) 'Could not gather sufficient random data' ); } +endif; diff --git a/wp-includes/random_compat/random_int.php b/wp-includes/random_compat/random_int.php index fd3ef87a22..84b539e02d 100644 --- a/wp-includes/random_compat/random_int.php +++ b/wp-includes/random_compat/random_int.php @@ -26,6 +26,7 @@ * SOFTWARE. */ +if ( ! is_callable( 'random_int' ) ): /** * Fetch a random integer between $min and $max inclusive * @@ -189,3 +190,4 @@ function random_int($min, $max) return (int) $val; } +endif;