From 67490f42e6dfc47cf57314b240b8636281d68773 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 14 Jul 2018 22:58:44 +0200 Subject: [PATCH] More type fixes --- Message/Http/Rest.php | 28 ++++++++++++++++------------ Module/InfoManager.php | 4 +++- Module/ModuleManager.php | 17 ++++++++++------- Module/PackageManager.php | 16 ++++++++++++---- Security/PhpCode.php | 9 +++++++-- 5 files changed, 48 insertions(+), 26 deletions(-) diff --git a/Message/Http/Rest.php b/Message/Http/Rest.php index 3bc67adea..edf7f29a0 100644 --- a/Message/Http/Rest.php +++ b/Message/Http/Rest.php @@ -36,35 +36,39 @@ final class Rest */ public static function request(Request $request) : string { - $curl = curl_init(); + $curl = \curl_init(); + + if ($curl === false) { + throw new \Exception(); + } switch ($request->getMethod()) { case RequestMethod::PUT: - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT'); + \curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT'); break; case RequestMethod::DELETE: - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); + \curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); break; } if ($request->getMethod() !== RequestMethod::GET) { - curl_setopt($curl, CURLOPT_POST, 1); + \curl_setopt($curl, CURLOPT_POST, 1); if ($request->getData() !== null) { - curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getData()); + \curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getData()); } } - curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($curl, CURLOPT_USERPWD, 'username:password'); + \curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + \curl_setopt($curl, CURLOPT_USERPWD, 'username:password'); - curl_setopt($curl, CURLOPT_URL, $request->__toString()); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + \curl_setopt($curl, CURLOPT_URL, $request->__toString()); + \curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - $result = curl_exec($curl); + $result = \curl_exec($curl); - curl_close($curl); + \curl_close($curl); - return $result; + return $result === false ? '' : $result; } } diff --git a/Module/InfoManager.php b/Module/InfoManager.php index 1518f2cb2..053290d0c 100644 --- a/Module/InfoManager.php +++ b/Module/InfoManager.php @@ -85,7 +85,9 @@ final class InfoManager throw new PathException($this->path); } - $this->info = \json_decode(file_get_contents($this->path), true); + $contents = \file_get_contents($this->path . '/info.json'); + $info = \json_decode($contents === false ? '[]' : $contents, true); + $this->info = $info === false ? [] : $info; } /** diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index 6ddaf99b9..f3e099b5f 100644 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -210,8 +210,9 @@ final class ModuleManager // throw new PathException($path); } - $json = \json_decode(file_get_contents($path), true); - $this->active[$json['name']['internal']] = $json; + $content = \file_get_contents($path); + $json = \json_decode($content === false ? '[]' : $content, true); + $this->active[$json['name']['internal']] = $json === false ? [] : $json; } break; default: @@ -260,8 +261,9 @@ final class ModuleManager // throw new PathException($path); } - $json = \json_decode(file_get_contents($path), true); - $this->all[$json['name']['internal']] = $json; + $content = \file_get_contents($path); + $json = \json_decode($content === false ? '[]' : $content, true); + $this->all[$json['name']['internal']] = $json === false ? [] : $json; } } @@ -306,8 +308,9 @@ final class ModuleManager // throw new PathException($path); } - $json = \json_decode(file_get_contents($path), true); - $this->installed[$json['name']['internal']] = $json; + $content = \file_get_contents($path); + $json = \json_decode($content === false ? '[]' : $content, true); + $this->installed[$json['name']['internal']] = $json === false ? [] : $json; } break; @@ -330,7 +333,7 @@ final class ModuleManager */ private function loadInfo(string $module) : InfoManager { - $path = realpath($oldPath = $this->modulePath . '/' . $module . '/info.json'); + $path = \realpath($oldPath = $this->modulePath . '/' . $module . '/info.json'); if ($path === false) { throw new PathException($oldPath); diff --git a/Module/PackageManager.php b/Module/PackageManager.php index b336ec7b6..d88d32bdb 100644 --- a/Module/PackageManager.php +++ b/Module/PackageManager.php @@ -109,7 +109,9 @@ final class PackageManager throw new PathException($this->extractPath); } - $this->info = \json_decode(file_get_contents($this->extractPath . '/info.json'), true); + $contents = \file_get_contents($this->extractPath . '/info.json'); + $info = \json_decode($contents === false ? '[]' : $contents, true); + $this->info = $info === false ? [] : $info; } /** @@ -121,7 +123,8 @@ final class PackageManager */ public function isValid() : bool { - return $this->authenticate(file_get_contents($this->extractPath . '/package.cert'), $this->hashFiles()); + $contents = \file_get_contents($this->extractPath . '/package.cert'); + return $this->authenticate($contents === false ? '' : $contents, $this->hashFiles()); } /** @@ -141,10 +144,15 @@ final class PackageManager continue; } - \sodium_crypto_generichash_update($state, \file_get_contents($this->extractPath . '/package/' . $file)); + $contents = \file_get_contents($this->extractPath . '/package/' . $file); + if ($contents === false) { + throw new \Exception(); + } + + \sodium_crypto_generichash_update($state, $contents); } - return \sodium_crypto_generichash_final(); + return \sodium_crypto_generichash_final($state); } /** diff --git a/Security/PhpCode.php b/Security/PhpCode.php index 716246bd9..b3d403141 100644 --- a/Security/PhpCode.php +++ b/Security/PhpCode.php @@ -104,7 +104,12 @@ final class PhpCode */ public static function isDisabled(array $functions) : bool { - $disabled = ini_get('disable_functions'); + $disabled = \ini_get('disable_functions'); + + if ($disabled === false) { + return true; + } + $disabled = \str_replace(' ', '', $disabled); $disabled = \explode(',', $disabled); @@ -149,6 +154,6 @@ final class PhpCode */ public static function validateFileIntegrity(string $source, string $hash) : bool { - return md5_file($source) === $hash; + return \md5_file($source) === $hash; } }