]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/random_compat/random_bytes_dev_urandom.php
WordPress 4.6.3-scripts
[autoinstalls/wordpress.git] / wp-includes / random_compat / random_bytes_dev_urandom.php
index aebcafcf7df8514742b6492f923acfd5767c9535..db93b075787138f267ac69e2cfcf121d94f39133 100644 (file)
@@ -62,18 +62,25 @@ function random_bytes($bytes)
                 $fp = false;
             }
         }
                 $fp = false;
             }
         }
-        /**
-         * stream_set_read_buffer() does not exist in HHVM
-         * 
-         * If we don't set the stream's read buffer to 0, PHP will
-         * internally buffer 8192 bytes, which can waste entropy
-         * 
-         * stream_set_read_buffer returns 0 on success
-         */
-        if (!empty($fp) && function_exists('stream_set_read_buffer')) {
-            stream_set_read_buffer($fp, RANDOM_COMPAT_READ_BUFFER);
+
+        if (!empty($fp)) {
+            /**
+             * stream_set_read_buffer() does not exist in HHVM
+             * 
+             * If we don't set the stream's read buffer to 0, PHP will
+             * internally buffer 8192 bytes, which can waste entropy
+             * 
+             * stream_set_read_buffer returns 0 on success
+             */
+            if (function_exists('stream_set_read_buffer')) {
+                stream_set_read_buffer($fp, RANDOM_COMPAT_READ_BUFFER);
+            }
+            if (function_exists('stream_set_chunk_size')) {
+                stream_set_chunk_size($fp, RANDOM_COMPAT_READ_BUFFER);
+            }
         }
     }
         }
     }
+
     try {
         $bytes = RandomCompat_intval($bytes);
     } catch (TypeError $ex) {
     try {
         $bytes = RandomCompat_intval($bytes);
     } catch (TypeError $ex) {
@@ -81,11 +88,13 @@ function random_bytes($bytes)
             'random_bytes(): $bytes must be an integer'
         );
     }
             'random_bytes(): $bytes must be an integer'
         );
     }
+
     if ($bytes < 1) {
         throw new Error(
             'Length must be greater than 0'
         );
     }
     if ($bytes < 1) {
         throw new Error(
             'Length must be greater than 0'
         );
     }
+
     /**
      * This if() block only runs if we managed to open a file handle
      * 
     /**
      * This if() block only runs if we managed to open a file handle
      * 
@@ -96,6 +105,7 @@ function random_bytes($bytes)
     if (!empty($fp)) {
         $remaining = $bytes;
         $buf = '';
     if (!empty($fp)) {
         $remaining = $bytes;
         $buf = '';
+
         /**
          * We use fread() in a loop to protect against partial reads
          */
         /**
          * We use fread() in a loop to protect against partial reads
          */
@@ -128,6 +138,7 @@ function random_bytes($bytes)
             }
         }
     }
             }
         }
     }
+
     /**
      * If we reach here, PHP has failed us.
      */
     /**
      * If we reach here, PHP has failed us.
      */