From 9ebc397b4dcb205ecfc10e27466d09f5bf63724f Mon Sep 17 00:00:00 2001
From: Oliver Bartsch <bo@cedev.de>
Date: Fri, 15 Mar 2024 18:08:07 +0100
Subject: [PATCH] [BUGFIX] Prevent null pointer exception in
 ContentObjectRenderer
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The $request might not be initialized, that's
why the getRequest() method has to be used in
ContentObjectRenderer.

This is now done for newly introduced occurrences,
accessing the class property directly.

Resolves: #103407
Releases: main
Change-Id: I466f31316b2885132288cbc8745f3dc4760bdcf2
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83497
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Benjamin Franzke <ben@bnf.dev>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Benjamin Franzke <ben@bnf.dev>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Benni Mack <benni@typo3.org>
---
 .../Classes/ContentObject/ContentObjectRenderer.php         | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
index 4b5b16fc5279..e0912cd35d74 100644
--- a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
+++ b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
@@ -4149,7 +4149,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
         if (is_array($altRootLine)) {
             $rootLine = $altRootLine;
         } else {
-            $rootLine = $this->request->getAttribute('frontend.page.information')->getLocalRootLine();
+            $rootLine = $this->getRequest()->getAttribute('frontend.page.information')->getLocalRootLine();
         }
         if (!$slideBack) {
             return $rootLine[$key][$field] ?? '';
@@ -4806,7 +4806,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
                 $pidList = GeneralUtility::trimExplode(',', $conf['pidInList'], true);
                 array_walk($pidList, function (&$storagePid) {
                     if ($storagePid === 'this') {
-                        $storagePid = $this->request->getAttribute('frontend.page.information')->getId();
+                        $storagePid = $this->getRequest()->getAttribute('frontend.page.information')->getId();
                     }
                 });
                 $pageRepository = $this->getPageRepository();
@@ -5170,7 +5170,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
             return [];
         }
 
-        if ($pageIds === [$this->request->getAttribute('frontend.page.information')->getId()]) {
+        if ($pageIds === [$this->getRequest()->getAttribute('frontend.page.information')->getId()]) {
             // Middlewares already checked access to the current page and made sure the current doktype
             // is a doktype whose content should be rendered, so there is no need to check that again.
             return $pageIds;
-- 
GitLab