From 41eb0d80122bcbd89d1e43527a9fb3871261f4dd Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Thu, 2 Apr 2020 14:32:12 -0400 Subject: [PATCH] Fix logic error reading random bytes from /dev/urandom Fixes a bug introduced in c2be7e648 Previously, this would return those bytes if the number of bytes read was **less than** the number of bytes this was trying to read. In practice, I believe this would mean bytes from /dev/urandom would never get used. (Noticed when upgrading phpseclib) --- phpseclib/Crypt/Random.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/Crypt/Random.php b/phpseclib/Crypt/Random.php index b7874ea11..6230a55e0 100644 --- a/phpseclib/Crypt/Random.php +++ b/phpseclib/Crypt/Random.php @@ -106,7 +106,7 @@ function crypt_random_string($length) } if ($fp !== true && $fp !== false) { // surprisingly faster than !is_bool() or is_resource() $temp = fread($fp, $length); - if (strlen($temp) != $length) { + if (strlen($temp) == $length) { return $temp; } }