From 4ce69f3a3def418673fa0ebffb24953a4d00c300 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Mon, 20 Feb 2023 18:12:02 +0100 Subject: [PATCH] Nicely exit in case of an early PHP type crash Signed-off-by: William Desportes --- libraries/classes/Header.php | 12 ++++++++---- libraries/classes/ResponseRenderer.php | 11 +++++++++-- libraries/classes/Url.php | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/libraries/classes/Header.php b/libraries/classes/Header.php index 36717f5ebb..788db33931 100644 --- a/libraries/classes/Header.php +++ b/libraries/classes/Header.php @@ -111,8 +111,12 @@ class Header $this->bodyId = ''; $this->title = ''; $this->console = new Console(); - $this->menu = new Menu($dbi, $db ?? '', $table ?? ''); - $this->menuEnabled = true; + $this->menuEnabled = false; + if ($dbi !== null) { + $this->menuEnabled = true; + $this->menu = new Menu($dbi, $db ?? '', $table ?? ''); + } + $this->warningsEnabled = true; $this->scripts = new Scripts(); $this->addDefaultScripts(); @@ -191,8 +195,8 @@ class Header 'LoginCookieValidity' => $GLOBALS['cfg']['LoginCookieValidity'], 'session_gc_maxlifetime' => (int) ini_get('session.gc_maxlifetime'), 'logged_in' => isset($dbi) ? $dbi->isConnected() : false, - 'is_https' => $GLOBALS['config']->isHttps(), - 'rootPath' => $GLOBALS['config']->getRootPath(), + 'is_https' => $GLOBALS['config'] !== null && $GLOBALS['config']->isHttps(), + 'rootPath' => $GLOBALS['config'] !== null && $GLOBALS['config']->getRootPath(), 'arg_separator' => Url::getArgSeparator(), 'version' => Version::VERSION, ]; diff --git a/libraries/classes/ResponseRenderer.php b/libraries/classes/ResponseRenderer.php index 95790034ef..014f194418 100644 --- a/libraries/classes/ResponseRenderer.php +++ b/libraries/classes/ResponseRenderer.php @@ -290,9 +290,16 @@ class ResponseRenderer // if its content was already rendered // and, in this case, the header will be // in the content part of the request - $retval = $this->header->getDisplay(); + $retval = ''; + if ($this->header !== null) { + $retval .= $this->header->getDisplay(); + } + $retval .= $this->HTML; - $retval .= $this->footer->getDisplay(); + + if ($this->footer !== null) { + $retval .= $this->footer->getDisplay(); + } return $retval; } diff --git a/libraries/classes/Url.php b/libraries/classes/Url.php index c6bf3f5ed1..6c3cc45a54 100644 --- a/libraries/classes/Url.php +++ b/libraries/classes/Url.php @@ -249,7 +249,7 @@ class Url $separator = self::getArgSeparator(); - if (! $encrypt || ! $config->get('URLQueryEncryption')) { + if (! $encrypt || $config === null || ! $config->get('URLQueryEncryption')) { return http_build_query($params, '', $separator); }