Skip to content

Commit

Permalink
Fix logic error reading random bytes from /dev/urandom
Browse files Browse the repository at this point in the history
Fixes a bug introduced in c2be7e6

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)
  • Loading branch information
TysonAndre authored and terrafrost committed Apr 3, 2020
1 parent 5e2951f commit 41eb0d8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion phpseclib/Crypt/Random.php
Expand Up @@ -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;
}
}
Expand Down

1 comment on commit 41eb0d8

@terrafrost
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1466

Please sign in to comment.