From be6d086949323c00e5e3e05b7e300987850a5389 Mon Sep 17 00:00:00 2001 From: Oliver Klee <typo3-coding@oliverklee.de> Date: Tue, 4 Apr 2023 11:46:05 +0200 Subject: [PATCH] [BUGFIX] Fix invalid array access in Mail\TransportFactory Even for a broken/imcomplete configuration, we want to have the exception that complains about the incomplete configuration instead of a `TypeError`. Also add some type casts to have predictable types in more cases. Resolves: #100431 Related: #100249 Releases: main, 11.5 Change-Id: If92af8f66bab7d311cbddc3178bc515b63381741 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/78452 Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: core-ci <typo3@b13.com> --- typo3/sysext/core/Classes/Mail/TransportFactory.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/typo3/sysext/core/Classes/Mail/TransportFactory.php b/typo3/sysext/core/Classes/Mail/TransportFactory.php index dda23206ec30..00c42bd41fff 100644 --- a/typo3/sysext/core/Classes/Mail/TransportFactory.php +++ b/typo3/sysext/core/Classes/Mail/TransportFactory.php @@ -75,7 +75,7 @@ class TransportFactory implements SingletonInterface, LoggerAwareInterface $transportType = isset($mailSettings['transport_spool_type']) && !empty($mailSettings['transport_spool_type']) - ? 'spool' : $mailSettings['transport']; + ? 'spool' : (string)$mailSettings['transport']; switch ($transportType) { case 'spool': @@ -140,8 +140,8 @@ class TransportFactory implements SingletonInterface, LoggerAwareInterface ); break; case 'mbox': - $mboxFile = $mailSettings['transport_mbox_file']; - if ($mboxFile == '') { + $mboxFile = (string)($mailSettings['transport_mbox_file'] ?? ''); + if ($mboxFile === '') { throw new Exception('$GLOBALS[\'TYPO3_CONF_VARS\'][\'MAIL\'][\'transport_mbox_file\'] needs to be set when transport is set to "mbox".', 1294586645); } // Create our transport @@ -193,9 +193,10 @@ class TransportFactory implements SingletonInterface, LoggerAwareInterface */ protected function createSpool(array $mailSettings): DelayedTransportInterface { - switch ($mailSettings['transport_spool_type']) { + $transportSpoolType = (string)($mailSettings['transport_spool_type'] ?? ''); + switch ($transportSpoolType) { case self::SPOOL_FILE: - $path = GeneralUtility::getFileAbsFileName($mailSettings['transport_spool_filepath']); + $path = GeneralUtility::getFileAbsFileName($mailSettings['transport_spool_filepath'] ?? ''); if (empty($path)) { throw new \RuntimeException('The Spool Type filepath must be configured for TYPO3 in order to be used. Be sure that it\'s not accessible via the web.', 1518558797); } @@ -214,7 +215,7 @@ class TransportFactory implements SingletonInterface, LoggerAwareInterface ); break; default: - $spool = GeneralUtility::makeInstance($mailSettings['transport_spool_type'], $mailSettings); + $spool = GeneralUtility::makeInstance($transportSpoolType, $mailSettings); if (!($spool instanceof DelayedTransportInterface)) { throw new \RuntimeException( $mailSettings['transport_spool_type'] . ' is not an implementation of DelayedTransportInterface, but must implement that interface to be used as a mail spool.', -- GitLab