diff --git a/src/pocketmine/plugin/PluginBase.php b/src/pocketmine/plugin/PluginBase.php index 19f3f70a7..5295b71c8 100644 --- a/src/pocketmine/plugin/PluginBase.php +++ b/src/pocketmine/plugin/PluginBase.php @@ -202,16 +202,17 @@ abstract class PluginBase implements Plugin{ $out = $this->dataFolder . $filename; if(!file_exists($this->dataFolder)){ - if(!file_exists($this->dataFolder)){ - mkdir($this->dataFolder, 0755, true); - } + mkdir($this->dataFolder, 0755, true); } if(file_exists($out) and $replace !== true){ return false; } - return stream_copy_to_stream($resource, fopen($out, "wb")) > 0; + $ret = stream_copy_to_stream($resource, $fp = fopen($out, "wb")) > 0; + fclose($fp); + fclose($resource); + return $ret; } /** @@ -257,6 +258,7 @@ abstract class PluginBase implements Plugin{ $this->config = new Config($this->configFile); if(($configStream = $this->getResource("config.yml")) !== null){ $this->config->setDefaults(yaml_parse(config::fixYAMLIndexes(stream_get_contents($configStream)))); + fclose($configStream); } } diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index 635342870..2499e1820 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -272,9 +272,18 @@ class Utils{ unset($weakEntropy); if($secure === true){ + + if(file_exists("/dev/urandom")){ + $fp = fopen("/dev/urandom", "rb"); + $systemRandom = fread($fp, 64); + fclose($fp); + }else{ + $systemRandom = str_repeat("\x00", 64); + } + $strongEntropyValues = [ is_array($startEntropy) ? hash("sha512", $startEntropy[($rounds + $drop) % count($startEntropy)], true) : hash("sha512", $startEntropy, true), //Get a random index of the startEntropy, or just read it - file_exists("/dev/urandom") ? fread(fopen("/dev/urandom", "rb"), 64) : str_repeat("\x00", 64), + $systemRandom, function_exists("openssl_random_pseudo_bytes") ? openssl_random_pseudo_bytes(64) : str_repeat("\x00", 64), function_exists("mcrypt_create_iv") ? mcrypt_create_iv(64, MCRYPT_DEV_URANDOM) : str_repeat("\x00", 64), $value,