From 35490ca41cf895cd77644e39d3a232f1be2bc4f1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 15 Mar 2020 15:46:03 +0000 Subject: [PATCH 1/4] CrashDump: do not assume that file() always returns array phpstan level 7 prep --- src/pocketmine/CrashDump.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/CrashDump.php b/src/pocketmine/CrashDump.php index 321210dcd4..fc67be6c8d 100644 --- a/src/pocketmine/CrashDump.php +++ b/src/pocketmine/CrashDump.php @@ -288,9 +288,11 @@ class CrashDump{ if($this->server->getProperty("auto-report.send-code", true) !== false and file_exists($error["fullFile"])){ $file = @file($error["fullFile"], FILE_IGNORE_NEW_LINES); - for($l = max(0, $error["line"] - 10); $l < $error["line"] + 10 and isset($file[$l]); ++$l){ - $this->addLine("[" . ($l + 1) . "] " . $file[$l]); - $this->data["code"][$l + 1] = $file[$l]; + if($file !== false){ + for($l = max(0, $error["line"] - 10); $l < $error["line"] + 10 and isset($file[$l]); ++$l){ + $this->addLine("[" . ($l + 1) . "] " . $file[$l]); + $this->data["code"][$l + 1] = $file[$l]; + } } } From 9c86763322d06c7c7a9b133c77107d16cbb73f01 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 15 Mar 2020 15:47:07 +0000 Subject: [PATCH 2/4] CrashDump: do not assume that error_get_last() always returns array this returns NULL if there was no error before the shutdown handler was triggered (usually caused by a plugin calling exit() prematurely). --- src/pocketmine/CrashDump.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/CrashDump.php b/src/pocketmine/CrashDump.php index fc67be6c8d..776989d247 100644 --- a/src/pocketmine/CrashDump.php +++ b/src/pocketmine/CrashDump.php @@ -228,7 +228,10 @@ class CrashDump{ if(isset($lastExceptionError)){ $error = $lastExceptionError; }else{ - $error = (array) error_get_last(); + $error = error_get_last(); + if($error === null){ + throw new \RuntimeException("Crash error information missing - did something use exit()?"); + } $error["trace"] = Utils::currentTrace(3); //Skipping CrashDump->baseCrash, CrashDump->construct, Server->crashDump $errorConversion = [ E_ERROR => "E_ERROR", From 5c7b05c2ba7a7202666b0b0246f68cbe78f28a93 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 15 Mar 2020 15:48:09 +0000 Subject: [PATCH 3/4] CrashDump: do not assign possibly-false return value of fopen() directly to non-union field this would become a problem with typed properties, and also phpstan level 7 doesn't like it. --- src/pocketmine/CrashDump.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/CrashDump.php b/src/pocketmine/CrashDump.php index 776989d247..49c0ff1703 100644 --- a/src/pocketmine/CrashDump.php +++ b/src/pocketmine/CrashDump.php @@ -117,10 +117,11 @@ class CrashDump{ mkdir($this->server->getDataPath() . "crashdumps"); } $this->path = $this->server->getDataPath() . "crashdumps/" . date("D_M_j-H.i.s-T_Y", $this->time) . ".log"; - $this->fp = @fopen($this->path, "wb"); - if(!is_resource($this->fp)){ + $fp = @fopen($this->path, "wb"); + if(!is_resource($fp)){ throw new \RuntimeException("Could not create Crash Dump"); } + $this->fp = $fp; $this->data["format_version"] = self::FORMAT_VERSION; $this->data["time"] = $this->time; $this->addLine($this->server->getName() . " Crash Dump " . date("D M j H:i:s T Y", $this->time)); From 06a9c98ded924c7857ea1830c5f0aa656b0b932c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 15 Mar 2020 15:49:04 +0000 Subject: [PATCH 4/4] MemoryManager: fix strict-rules error on phpstan level 7 --- src/pocketmine/MemoryManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/MemoryManager.php b/src/pocketmine/MemoryManager.php index 4f3d2226b4..344a1fe2fd 100644 --- a/src/pocketmine/MemoryManager.php +++ b/src/pocketmine/MemoryManager.php @@ -404,8 +404,8 @@ class MemoryManager{ "properties" => [] ]; - if($reflection->getParentClass()){ - $info["parent"] = $reflection->getParentClass()->getName(); + if(($parent = $reflection->getParentClass()) !== false){ + $info["parent"] = $parent->getName(); } if(count($reflection->getInterfaceNames()) > 0){