From: Sascha Schumann Date: Tue, 25 Jul 2000 22:17:20 +0000 (+0000) Subject: Read from /dev/u?random until the buffer is filled. X-Git-Tag: PRE_FILE_COMPILE_API_CHANGE~139 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=79186d4fe9d5b211a3c7f2ff98b8694c2d54ec12;p=php Read from /dev/u?random until the buffer is filled. Submitted by: Derick Rethans --- diff --git a/ext/mcrypt/mcrypt.c b/ext/mcrypt/mcrypt.c index 9f18aaa832..c52a4291f6 100644 --- a/ext/mcrypt/mcrypt.c +++ b/ext/mcrypt/mcrypt.c @@ -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) {