X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/138998bbd8f7a1ac38b2f1eacbdf7cd522be4b13..8d3bb1a5dcfdea9857d3c88c3751f09593e34dc8:/wp-includes/random_compat/random_bytes_openssl.php diff --git a/wp-includes/random_compat/random_bytes_openssl.php b/wp-includes/random_compat/random_bytes_openssl.php index 3e12d3da..62bf7703 100644 --- a/wp-includes/random_compat/random_bytes_openssl.php +++ b/wp-includes/random_compat/random_bytes_openssl.php @@ -48,12 +48,13 @@ function random_bytes($bytes) 'random_bytes(): $bytes must be an integer' ); } + if ($bytes < 1) { throw new Error( 'Length must be greater than 0' ); } - $secure = true; + /** * $secure is passed by reference. If it's set to false, fail. Note * that this will only return false if this function fails to return @@ -61,12 +62,18 @@ function random_bytes($bytes) * * @ref https://github.com/paragonie/random_compat/issues/6#issuecomment-119564973 */ + $secure = true; $buf = openssl_random_pseudo_bytes($bytes, $secure); - if ($buf !== false && $secure) { - if (RandomCompat_strlen($buf) === $bytes) { - return $buf; - } + if ( + $buf !== false + && + $secure + && + RandomCompat_strlen($buf) === $bytes + ) { + return $buf; } + /** * If we reach here, PHP has failed us. */