From 978a312ce8ca801847aea60dafa8b905cf9dbbce 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 e5c819c76..8f53eb319 100644 --- a/phpseclib/Crypt/Random.php +++ b/phpseclib/Crypt/Random.php @@ -98,7 +98,7 @@ static function 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; } }