]> granicus.if.org Git - php/commitdiff
Read from /dev/u?random until the buffer is filled.
authorSascha Schumann <sas@php.net>
Tue, 25 Jul 2000 22:17:20 +0000 (22:17 +0000)
committerSascha Schumann <sas@php.net>
Tue, 25 Jul 2000 22:17:20 +0000 (22:17 +0000)
Submitted by: Derick Rethans <d.rethans@jdimedia.nl>

ext/mcrypt/mcrypt.c

index 9f18aaa832f1e43bfd7b041424b989d06f352bd7..c52a4291f64a66960d4bec1b7fe3b76bc1d414b0 100644 (file)
@@ -205,6 +205,7 @@ PHP_FUNCTION(mcrypt_create_iv)
        
        if(source == RANDOM || source == URANDOM) {
                int fd;
+               size_t read_bytes = 0;
 
                fd = open(source == RANDOM ? "/dev/random" : "/dev/urandom",
                                O_RDONLY);
@@ -213,7 +214,13 @@ PHP_FUNCTION(mcrypt_create_iv)
                        php_error(E_WARNING, "cannot open source device");
                        RETURN_FALSE;
                }
-               n = read(fd, iv, i);
+               while (read_bytes < i) {
+                       n = read(fd, iv + read_bytes, i - read_bytes);
+                       if (n < 0)
+                               break;
+                       read_bytes += n;
+               }
+               n = read_bytes;
                close(fd);
        } else {
                while(i) {