mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-16 10:15:14 +00: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
|
// see http://en.wikipedia.org/wiki//dev/random
|
||||||
// if open_basedir is enabled file_exists() will ouput an "open_basedir restriction in effect" warning,
|
static $urandom = true;
|
||||||
// so we suppress it.
|
if ($urandom === true) {
|
||||||
if (@file_exists('/dev/urandom')) {
|
// Warning's will be output unles the error suppression operator is used. Errors such as
|
||||||
static $fp;
|
// "open_basedir restriction in effect", "Permission denied", "No such file or directory", etc.
|
||||||
if (!$fp) {
|
$urandom = @fopen('/dev/urandom', 'rb');
|
||||||
$fp = fopen('/dev/urandom', 'rb');
|
|
||||||
}
|
}
|
||||||
|
if (!is_bool($urandom)) {
|
||||||
extract(unpack('Nrandom', fread($fp, 4)));
|
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:
|
// 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