<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[36886] trunk/src/wp-includes/random_compat: Update Random_Compat from 1.1.6 to 1.2.1.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/36886">36886</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/36886","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>ocean90</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-03-08 17:14:52 +0000 (Tue, 08 Mar 2016)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/35665">#35665</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesrandom_compatbyte_safe_stringsphp">trunk/src/wp-includes/random_compat/byte_safe_strings.php</a></li>
<li><a href="#trunksrcwpincludesrandom_compatcast_to_intphp">trunk/src/wp-includes/random_compat/cast_to_int.php</a></li>
<li><a href="#trunksrcwpincludesrandom_compatrandomphp">trunk/src/wp-includes/random_compat/random.php</a></li>
<li><a href="#trunksrcwpincludesrandom_compatrandom_bytes_com_dotnetphp">trunk/src/wp-includes/random_compat/random_bytes_com_dotnet.php</a></li>
<li><a href="#trunksrcwpincludesrandom_compatrandom_bytes_dev_urandomphp">trunk/src/wp-includes/random_compat/random_bytes_dev_urandom.php</a></li>
<li><a href="#trunksrcwpincludesrandom_compatrandom_bytes_libsodiumphp">trunk/src/wp-includes/random_compat/random_bytes_libsodium.php</a></li>
<li><a href="#trunksrcwpincludesrandom_compatrandom_bytes_libsodium_legacyphp">trunk/src/wp-includes/random_compat/random_bytes_libsodium_legacy.php</a></li>
<li><a href="#trunksrcwpincludesrandom_compatrandom_bytes_mcryptphp">trunk/src/wp-includes/random_compat/random_bytes_mcrypt.php</a></li>
<li><a href="#trunksrcwpincludesrandom_compatrandom_bytes_opensslphp">trunk/src/wp-includes/random_compat/random_bytes_openssl.php</a></li>
<li><a href="#trunksrcwpincludesrandom_compatrandom_intphp">trunk/src/wp-includes/random_compat/random_int.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesrandom_compatbyte_safe_stringsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/random_compat/byte_safe_strings.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/random_compat/byte_safe_strings.php 2016-03-08 16:44:25 UTC (rev 36885)
+++ trunk/src/wp-includes/random_compat/byte_safe_strings.php 2016-03-08 17:14:52 UTC (rev 36886)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -50,8 +50,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'RandomCompat_strlen() expects a string'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return mb_strlen($binary_string, '8bit');
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * strlen() implementation that isn't brittle to mbstring.func_overload
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -77,8 +79,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if (!function_exists('RandomCompat_substr')) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if (
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- defined('MB_OVERLOAD_STRING') &&
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ defined('MB_OVERLOAD_STRING')
+ &&
</ins><span class="cx" style="display: block; padding: 0 10px"> ini_get('mbstring.func_overload') & MB_OVERLOAD_STRING
</span><span class="cx" style="display: block; padding: 0 10px"> ) {
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -102,11 +106,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'RandomCompat_substr(): First argument should be a string'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if (!is_int($start)) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new TypeError(
</span><span class="cx" style="display: block; padding: 0 10px"> 'RandomCompat_substr(): Second argument should be an integer'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($length === null) {
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * mb_substr($str, 0, NULL, '8bit') returns an empty string on
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -118,9 +124,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'RandomCompat_substr(): Third argument should be an integer, or omitted'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return mb_substr($binary_string, $start, $length, '8bit');
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * substr() implementation that isn't brittle to mbstring.func_overload
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -141,19 +150,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'RandomCompat_substr(): First argument should be a string'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if (!is_int($start)) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new TypeError(
</span><span class="cx" style="display: block; padding: 0 10px"> 'RandomCompat_substr(): Second argument should be an integer'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($length !== null) {
</span><span class="cx" style="display: block; padding: 0 10px"> if (!is_int($length)) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new TypeError(
</span><span class="cx" style="display: block; padding: 0 10px"> 'RandomCompat_substr(): Third argument should be an integer, or omitted'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return substr($binary_string, $start, $length);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return substr($binary_string, $start);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesrandom_compatcast_to_intphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/random_compat/cast_to_int.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/random_compat/cast_to_int.php 2016-03-08 16:44:25 UTC (rev 36885)
+++ trunk/src/wp-includes/random_compat/cast_to_int.php 2016-03-08 17:14:52 UTC (rev 36886)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -37,26 +37,33 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * lose precision, so the <= and => operators might accidentally let a float
</span><span class="cx" style="display: block; padding: 0 10px"> * through.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param numeric $number The number we want to convert to an int
- * @param boolean $fail_open Set to true to not throw an exception
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int|float $number The number we want to convert to an int
+ * @param boolean $fail_open Set to true to not throw an exception
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @return int (or float if $fail_open)
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
+ * @throws TypeError
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function RandomCompat_intval($number, $fail_open = false)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> if (is_numeric($number)) {
</span><span class="cx" style="display: block; padding: 0 10px"> $number += 0;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if (
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- is_float($number) &&
- $number > ~PHP_INT_MAX &&
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ is_float($number)
+ &&
+ $number > ~PHP_INT_MAX
+ &&
</ins><span class="cx" style="display: block; padding: 0 10px"> $number < PHP_INT_MAX
</span><span class="cx" style="display: block; padding: 0 10px"> ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $number = (int) $number;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if (is_int($number) || $fail_open) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $number;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> throw new TypeError(
</span><span class="cx" style="display: block; padding: 0 10px"> 'Expected an integer.'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span></span></pre></div>
<a id="trunksrcwpincludesrandom_compatrandomphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/random_compat/random.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/random_compat/random.php 2016-03-08 16:44:25 UTC (rev 36885)
+++ trunk/src/wp-includes/random_compat/random.php 2016-03-08 17:14:52 UTC (rev 36886)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,22 +1,25 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Random_* Compatibility Library
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Random_* Compatibility Library
</ins><span class="cx" style="display: block; padding: 0 10px"> * for using the new PHP 7 random_* API in PHP 5 projects
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
+ * @version 1.2.1
+ * @released 2016-02-29
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * The MIT License (MIT)
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * Copyright (c) 2015 Paragon Initiative Enterprises
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * Permission is hereby granted, free of charge, to any person obtaining a copy
</span><span class="cx" style="display: block; padding: 0 10px"> * of this software and associated documentation files (the "Software"), to deal
</span><span class="cx" style="display: block; padding: 0 10px"> * in the Software without restriction, including without limitation the rights
</span><span class="cx" style="display: block; padding: 0 10px"> * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
</span><span class="cx" style="display: block; padding: 0 10px"> * copies of the Software, and to permit persons to whom the Software is
</span><span class="cx" style="display: block; padding: 0 10px"> * furnished to do so, subject to the following conditions:
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * The above copyright notice and this permission notice shall be included in
</span><span class="cx" style="display: block; padding: 0 10px"> * all copies or substantial portions of the Software.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
</span><span class="cx" style="display: block; padding: 0 10px"> * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
</span><span class="cx" style="display: block; padding: 0 10px"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -29,31 +32,41 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if (!defined('PHP_VERSION_ID')) {
</span><span class="cx" style="display: block; padding: 0 10px"> // This constant was introduced in PHP 5.2.7
</span><span class="cx" style="display: block; padding: 0 10px"> $RandomCompatversion = explode('.', PHP_VERSION);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- define('PHP_VERSION_ID', ($RandomCompatversion[0] * 10000 + $RandomCompatversion[1] * 100 + $RandomCompatversion[2]));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ define(
+ 'PHP_VERSION_ID',
+ $RandomCompatversion[0] * 10000
+ + $RandomCompatversion[1] * 100
+ + $RandomCompatversion[2]
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> $RandomCompatversion = null;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if (PHP_VERSION_ID < 70000) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if (!defined('RANDOM_COMPAT_READ_BUFFER')) {
</span><span class="cx" style="display: block; padding: 0 10px"> define('RANDOM_COMPAT_READ_BUFFER', 8);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $RandomCompatDIR = dirname(__FILE__);
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> require_once $RandomCompatDIR.'/byte_safe_strings.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require_once $RandomCompatDIR.'/cast_to_int.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require_once $RandomCompatDIR.'/error_polyfill.php';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if (!function_exists('random_bytes')) {
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * PHP 5.2.0 - 5.6.x way to implement random_bytes()
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * We use conditional statements here to define the function in accordance
</span><span class="cx" style="display: block; padding: 0 10px"> * to the operating environment. It's a micro-optimization.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * In order of preference:
</span><span class="cx" style="display: block; padding: 0 10px"> * 1. Use libsodium if available.
</span><span class="cx" style="display: block; padding: 0 10px"> * 2. fread() /dev/urandom if available (never on Windows)
</span><span class="cx" style="display: block; padding: 0 10px"> * 3. mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM)
</span><span class="cx" style="display: block; padding: 0 10px"> * 4. COM('CAPICOM.Utilities.1')->GetRandom()
</span><span class="cx" style="display: block; padding: 0 10px"> * 5. openssl_random_pseudo_bytes() (absolute last resort)
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * See ERRATA.md for our reasoning behind this particular order
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> if (extension_loaded('libsodium')) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -64,6 +77,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> require_once $RandomCompatDIR.'/random_bytes_libsodium_legacy.php';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Reading directly from /dev/urandom:
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -72,6 +86,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // way to exclude Windows.
</span><span class="cx" style="display: block; padding: 0 10px"> $RandomCompatUrandom = true;
</span><span class="cx" style="display: block; padding: 0 10px"> $RandomCompat_basedir = ini_get('open_basedir');
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if (!empty($RandomCompat_basedir)) {
</span><span class="cx" style="display: block; padding: 0 10px"> $RandomCompat_open_basedir = explode(
</span><span class="cx" style="display: block; padding: 0 10px"> PATH_SEPARATOR,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -83,46 +98,61 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> $RandomCompat_open_basedir = null;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if (
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- !function_exists('random_bytes') &&
- $RandomCompatUrandom &&
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ !function_exists('random_bytes')
+ &&
+ $RandomCompatUrandom
+ &&
</ins><span class="cx" style="display: block; padding: 0 10px"> @is_readable('/dev/urandom')
</span><span class="cx" style="display: block; padding: 0 10px"> ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Error suppression on is_readable() in case of an open_basedir
</span><span class="cx" style="display: block; padding: 0 10px"> // or safe_mode failure. All we care about is whether or not we
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // can read it at this point. If the PHP environment is going to
- // panic over trying to see if the file can be read in the first
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // can read it at this point. If the PHP environment is going to
+ // panic over trying to see if the file can be read in the first
</ins><span class="cx" style="display: block; padding: 0 10px"> // place, that is not helpful to us here.
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // See random_bytes_dev_urandom.php
</span><span class="cx" style="display: block; padding: 0 10px"> require_once $RandomCompatDIR.'/random_bytes_dev_urandom.php';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> // Unset variables after use
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $RandomCompat_basedir = null;
</ins><span class="cx" style="display: block; padding: 0 10px"> $RandomCompatUrandom = null;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $RandomCompat_basedir = null;
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * mcrypt_create_iv()
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> if (
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- !function_exists('random_bytes') &&
- PHP_VERSION_ID >= 50307 &&
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ !function_exists('random_bytes')
+ &&
+ PHP_VERSION_ID >= 50307
+ &&
</ins><span class="cx" style="display: block; padding: 0 10px"> extension_loaded('mcrypt')
</span><span class="cx" style="display: block; padding: 0 10px"> ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // See random_bytes_mcrypt.php
- require_once $RandomCompatDIR.'/random_bytes_mcrypt.php';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Prevent this code from hanging indefinitely on non-Windows;
+ // see https://bugs.php.net/bug.php?id=69833
+ if (
+ DIRECTORY_SEPARATOR !== '/' ||
+ (PHP_VERSION_ID <= 50609 || PHP_VERSION_ID >= 50613)
+ ) {
+ // See random_bytes_mcrypt.php
+ require_once $RandomCompatDIR.'/random_bytes_mcrypt.php';
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if (
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- !function_exists('random_bytes') &&
- extension_loaded('com_dotnet') &&
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ !function_exists('random_bytes')
+ &&
+ extension_loaded('com_dotnet')
+ &&
</ins><span class="cx" style="display: block; padding: 0 10px"> class_exists('COM')
</span><span class="cx" style="display: block; padding: 0 10px"> ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $RandomCompat_disabled_classes = preg_split(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '#\s*,\s*#',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ '#\s*,\s*#',
</ins><span class="cx" style="display: block; padding: 0 10px"> strtolower(ini_get('disable_classes'))
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if (!in_array('com', $RandomCompat_disabled_classes)) {
</span><span class="cx" style="display: block; padding: 0 10px"> try {
</span><span class="cx" style="display: block; padding: 0 10px"> $RandomCompatCOMtest = new COM('CAPICOM.Utilities.1');
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -137,27 +167,31 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $RandomCompat_disabled_classes = null;
</span><span class="cx" style="display: block; padding: 0 10px"> $RandomCompatCOMtest = null;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * openssl_random_pseudo_bytes()
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> if (
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- !function_exists('random_bytes') &&
- extension_loaded('openssl') &&
</del><span class="cx" style="display: block; padding: 0 10px"> (
</span><span class="cx" style="display: block; padding: 0 10px"> // Unix-like with PHP >= 5.3.0 or
</span><span class="cx" style="display: block; padding: 0 10px"> (
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- DIRECTORY_SEPARATOR === '/' &&
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ DIRECTORY_SEPARATOR === '/'
+ &&
</ins><span class="cx" style="display: block; padding: 0 10px"> PHP_VERSION_ID >= 50300
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- ) ||
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ )
+ ||
</ins><span class="cx" style="display: block; padding: 0 10px"> // Windows with PHP >= 5.4.1
</span><span class="cx" style="display: block; padding: 0 10px"> PHP_VERSION_ID >= 50401
</span><span class="cx" style="display: block; padding: 0 10px"> )
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ &&
+ !function_exists('random_bytes')
+ &&
+ extension_loaded('openssl')
</ins><span class="cx" style="display: block; padding: 0 10px"> ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // See random_bytes_openssl.php
</span><span class="cx" style="display: block; padding: 0 10px"> require_once $RandomCompatDIR.'/random_bytes_openssl.php';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * throw new Exception
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -174,8 +208,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if (!function_exists('random_int')) {
</span><span class="cx" style="display: block; padding: 0 10px"> require_once $RandomCompatDIR.'/random_int.php';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $RandomCompatDIR = null;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesrandom_compatrandom_bytes_com_dotnetphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/random_compat/random_bytes_com_dotnet.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/random_compat/random_bytes_com_dotnet.php 2016-03-08 16:44:25 UTC (rev 36885)
+++ trunk/src/wp-includes/random_compat/random_bytes_com_dotnet.php 2016-03-08 17:14:52 UTC (rev 36886)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -46,14 +46,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'random_bytes(): $bytes must be an integer'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($bytes < 1) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new Error(
</span><span class="cx" style="display: block; padding: 0 10px"> 'Length must be greater than 0'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $buf = '';
</span><span class="cx" style="display: block; padding: 0 10px"> $util = new COM('CAPICOM.Utilities.1');
</span><span class="cx" style="display: block; padding: 0 10px"> $execCount = 0;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Let's not let it loop forever. If we run N times and fail to
</span><span class="cx" style="display: block; padding: 0 10px"> * get N bytes of random data, then CAPICOM has failed us.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -68,6 +71,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> ++$execCount;
</span><span class="cx" style="display: block; padding: 0 10px"> } while ($execCount < $bytes);
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * If we reach here, PHP has failed us.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span></span></pre></div>
<a id="trunksrcwpincludesrandom_compatrandom_bytes_dev_urandomphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/random_compat/random_bytes_dev_urandom.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/random_compat/random_bytes_dev_urandom.php 2016-03-08 16:44:25 UTC (rev 36885)
+++ trunk/src/wp-includes/random_compat/random_bytes_dev_urandom.php 2016-03-08 17:14:52 UTC (rev 36886)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -62,6 +62,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $fp = false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if (!empty($fp)) {
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * stream_set_read_buffer() does not exist in HHVM
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -79,6 +80,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> try {
</span><span class="cx" style="display: block; padding: 0 10px"> $bytes = RandomCompat_intval($bytes);
</span><span class="cx" style="display: block; padding: 0 10px"> } catch (TypeError $ex) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -86,11 +88,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'random_bytes(): $bytes must be an integer'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($bytes < 1) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new Error(
</span><span class="cx" style="display: block; padding: 0 10px"> 'Length must be greater than 0'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * This if() block only runs if we managed to open a file handle
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -101,6 +105,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if (!empty($fp)) {
</span><span class="cx" style="display: block; padding: 0 10px"> $remaining = $bytes;
</span><span class="cx" style="display: block; padding: 0 10px"> $buf = '';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * We use fread() in a loop to protect against partial reads
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -133,6 +138,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * If we reach here, PHP has failed us.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span></span></pre></div>
<a id="trunksrcwpincludesrandom_compatrandom_bytes_libsodiumphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/random_compat/random_bytes_libsodium.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/random_compat/random_bytes_libsodium.php 2016-03-08 16:44:25 UTC (rev 36885)
+++ trunk/src/wp-includes/random_compat/random_bytes_libsodium.php 2016-03-08 17:14:52 UTC (rev 36886)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -48,11 +48,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'random_bytes(): $bytes must be an integer'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($bytes < 1) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new Error(
</span><span class="cx" style="display: block; padding: 0 10px"> 'Length must be greater than 0'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * \Sodium\randombytes_buf() doesn't allow more than 2147483647 bytes to be
</span><span class="cx" style="display: block; padding: 0 10px"> * generated in one invocation.
</span></span></pre></div>
<a id="trunksrcwpincludesrandom_compatrandom_bytes_libsodium_legacyphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/random_compat/random_bytes_libsodium_legacy.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/random_compat/random_bytes_libsodium_legacy.php 2016-03-08 16:44:25 UTC (rev 36885)
+++ trunk/src/wp-includes/random_compat/random_bytes_libsodium_legacy.php 2016-03-08 17:14:52 UTC (rev 36886)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -48,11 +48,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'random_bytes(): $bytes must be an integer'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($bytes < 1) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new Error(
</span><span class="cx" style="display: block; padding: 0 10px"> 'Length must be greater than 0'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * \Sodium\randombytes_buf() doesn't allow more than 2147483647 bytes to be
</span><span class="cx" style="display: block; padding: 0 10px"> * generated in one invocation.
</span></span></pre></div>
<a id="trunksrcwpincludesrandom_compatrandom_bytes_mcryptphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/random_compat/random_bytes_mcrypt.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/random_compat/random_bytes_mcrypt.php 2016-03-08 16:44:25 UTC (rev 36885)
+++ trunk/src/wp-includes/random_compat/random_bytes_mcrypt.php 2016-03-08 17:14:52 UTC (rev 36886)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -48,6 +48,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'random_bytes(): $bytes must be an integer'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($bytes < 1) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new Error(
</span><span class="cx" style="display: block; padding: 0 10px"> 'Length must be greater than 0'
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -55,14 +56,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $buf = @mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($buf !== false) {
- if (RandomCompat_strlen($buf) === $bytes) {
- /**
- * Return our random entropy buffer here:
- */
- return $buf;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (
+ $buf !== false
+ &&
+ RandomCompat_strlen($buf) === $bytes
+ ) {
+ /**
+ * Return our random entropy buffer here:
+ */
+ return $buf;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * If we reach here, PHP has failed us.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span></span></pre></div>
<a id="trunksrcwpincludesrandom_compatrandom_bytes_opensslphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/random_compat/random_bytes_openssl.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/random_compat/random_bytes_openssl.php 2016-03-08 16:44:25 UTC (rev 36885)
+++ trunk/src/wp-includes/random_compat/random_bytes_openssl.php 2016-03-08 17:14:52 UTC (rev 36886)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -48,12 +48,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'random_bytes(): $bytes must be an integer'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($bytes < 1) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new Error(
</span><span class="cx" style="display: block; padding: 0 10px"> 'Length must be greater than 0'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $secure = true;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * $secure is passed by reference. If it's set to false, fail. Note
</span><span class="cx" style="display: block; padding: 0 10px"> * that this will only return false if this function fails to return
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -61,12 +62,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ref https://github.com/paragonie/random_compat/issues/6#issuecomment-119564973
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $secure = true;
</ins><span class="cx" style="display: block; padding: 0 10px"> $buf = openssl_random_pseudo_bytes($bytes, $secure);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($buf !== false && $secure) {
- if (RandomCompat_strlen($buf) === $bytes) {
- return $buf;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (
+ $buf !== false
+ &&
+ $secure
+ &&
+ RandomCompat_strlen($buf) === $bytes
+ ) {
+ return $buf;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * If we reach here, PHP has failed us.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span></span></pre></div>
<a id="trunksrcwpincludesrandom_compatrandom_intphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/random_compat/random_int.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/random_compat/random_int.php 2016-03-08 16:44:25 UTC (rev 36885)
+++ trunk/src/wp-includes/random_compat/random_int.php 2016-03-08 17:14:52 UTC (rev 36886)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -55,6 +55,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'random_int(): $min must be an integer'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> try {
</span><span class="cx" style="display: block; padding: 0 10px"> $max = RandomCompat_intval($max);
</span><span class="cx" style="display: block; padding: 0 10px"> } catch (TypeError $ex) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -73,6 +74,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'Minimum value must be less than or equal to the maximum value'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($max === $min) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $min;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -98,6 +100,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Test for integer overflow:
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> if (!is_int($range)) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Still safely calculate wider ranges.
</span><span class="cx" style="display: block; padding: 0 10px"> * Provided by @CodesInChaos, @oittaa
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -111,7 +114,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $bytes = PHP_INT_SIZE;
</span><span class="cx" style="display: block; padding: 0 10px"> $mask = ~0;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * $bits is effectively ceil(log($range, 2)) without dealing with
</span><span class="cx" style="display: block; padding: 0 10px"> * type juggling
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -181,5 +186,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * then try again.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> } while (!is_int($val) || $val > $max || $val < $min);
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return (int) $val;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>