]> granicus.if.org Git - php/commitdiff
Update random.c
authorScott <scott@paragonie.com>
Wed, 21 Oct 2015 20:04:34 +0000 (16:04 -0400)
committerAnatol Belski <ab@php.net>
Tue, 8 Dec 2015 12:16:48 +0000 (13:16 +0100)
Supersedes #1589

ext/standard/random.c

index 5fbb46018442ad088eb304bafd8b75e9cd976683..7dbc379459f97a5ad35357e54b1d0e65fd3144fb 100644 (file)
@@ -102,7 +102,6 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, zend_bool should_throw)
 
        /* Keep reading until we get enough entropy */
        do {
-               amount_to_read = size - read_bytes;
                /* Below, (bytes + read_bytes)  is pointer arithmetic.
 
                   bytes   read_bytes  size
@@ -112,6 +111,7 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, zend_bool should_throw)
                              amount_to_read
 
                */
+               amount_to_read = size - read_bytes;
                n = syscall(SYS_getrandom, bytes + read_bytes, amount_to_read, 0);
 
                if (n == -1) {