From 3026ddc180552a4bc5cfad3ae4d5ff02ceff89ff Mon Sep 17 00:00:00 2001 From: Oliver Bartsch <bo@cedev.de> Date: Fri, 20 Aug 2021 19:04:59 +0200 Subject: [PATCH] [TASK] Fix possible null pointer exception AbstractTreeView defines the current "scriptUrl", to build links in the backend. Since this class may also be called via CLI, e.g. by EXT:impexp, missing `instanceof` checks are added to prevent a null pointer exception. Resolves: #94947 Related: #93158 Releases: master Change-Id: I795effd17d42944ae0ab32b1ab10cd632ca7c31e Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70689 Tested-by: core-ci <typo3@b13.com> Tested-by: Alexander Nitsche <typo3@alexandernitsche.com> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Alexander Nitsche <typo3@alexandernitsche.com> Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../backend/Classes/Tree/View/AbstractTreeView.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/typo3/sysext/backend/Classes/Tree/View/AbstractTreeView.php b/typo3/sysext/backend/Classes/Tree/View/AbstractTreeView.php index 6a74f6741e21..913319c8ec24 100644 --- a/typo3/sysext/backend/Classes/Tree/View/AbstractTreeView.php +++ b/typo3/sysext/backend/Classes/Tree/View/AbstractTreeView.php @@ -15,6 +15,8 @@ namespace TYPO3\CMS\Backend\Tree\View; +use Psr\Http\Message\ServerRequestInterface; +use TYPO3\CMS\Backend\Routing\Route; use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; @@ -176,9 +178,13 @@ abstract class AbstractTreeView */ protected function determineScriptUrl() { - $this->thisScript = (string)GeneralUtility::makeInstance(UriBuilder::class)->buildUriFromRoutePath( - $GLOBALS['TYPO3_REQUEST']->getAttribute('route')->getPath() - ); + if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface + && ($route = $GLOBALS['TYPO3_REQUEST']->getAttribute('route')) instanceof Route + ) { + $this->thisScript = (string)GeneralUtility::makeInstance(UriBuilder::class)->buildUriFromRoutePath( + $route->getPath() + ); + } } /** -- GitLab