mirror of
https://github.com/danog/phpseclib.git
synced 2024-11-27 12:55:58 +01:00
- fopen() can fail even when file_exists() succeeds (thanks, dakitiger!)
git-svn-id: http://phpseclib.svn.sourceforge.net/svnroot/phpseclib/trunk@142 21d32557-59b3-4da0-833f-c5933fad653e
This commit is contained in:
parent
80bf62d6fc
commit
5eea5be210
@ -61,13 +61,13 @@ function crypt_random($min = 0, $max = 0x7FFFFFFF)
|
||||
}
|
||||
|
||||
// see http://en.wikipedia.org/wiki//dev/random
|
||||
// if open_basedir is enabled file_exists() will ouput an "open_basedir restriction in effect" warning,
|
||||
// so we suppress it.
|
||||
if (@file_exists('/dev/urandom')) {
|
||||
static $fp;
|
||||
if (!$fp) {
|
||||
$fp = fopen('/dev/urandom', 'rb');
|
||||
static $urandom = true;
|
||||
if ($urandom === true) {
|
||||
// Warning's will be output unles the error suppression operator is used. Errors such as
|
||||
// "open_basedir restriction in effect", "Permission denied", "No such file or directory", etc.
|
||||
$urandom = @fopen('/dev/urandom', 'rb');
|
||||
}
|
||||
if (!is_bool($urandom)) {
|
||||
extract(unpack('Nrandom', fread($fp, 4)));
|
||||
|
||||
// say $min = 0 and $max = 3. if we didn't do abs() then we could have stuff like this:
|
||||
|
Loading…
Reference in New Issue
Block a user