]> git.mxchange.org Git - friendica.git/commitdiff
Ward against preg_replace_callback null return value in Strings::performWithEscapedBlocks
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 2 Dec 2022 13:10:16 +0000 (08:10 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sat, 3 Dec 2022 09:20:27 +0000 (04:20 -0500)
- Add logging to troubleshoot potential issue with regex
- Address part of https://github.com/friendica/friendica/issues/12011#issuecomment-1335124938

src/Util/Strings.php

index 0d7bf66911d0eec156de1fb09c2e9c1f0dfc1630..379f2a25213dda4ed89fc8d688eb4dffb4c038f6 100644 (file)
@@ -23,6 +23,7 @@ namespace Friendica\Util;
 
 use Friendica\Content\ContactSelector;
 use Friendica\Core\Logger;
+use Friendica\Core\System;
 use ParagonIE\ConstantTime\Base64;
 
 /**
@@ -480,7 +481,7 @@ class Strings
 
                $blocks = [];
 
-               $text = preg_replace_callback($regex,
+               $return = preg_replace_callback($regex,
                        function ($matches) use ($executionId, &$blocks) {
                                $return = '«block-' . $executionId . '-' . count($blocks) . '»';
 
@@ -491,7 +492,11 @@ class Strings
                        $text
                );
 
-               $text = $callback($text) ?? '';
+               if (is_null($return)) {
+                       Logger::warning('Received null value from preg_replace_callback', ['text' => $text, 'regex' => $regex, 'blocks' => $blocks, 'executionId' => $executionId, 'callstack' => System::callstack(10)]);
+               }
+
+               $text = $callback($return ?? $text) ?? '';
 
                // Restore code blocks
                $text = preg_replace_callback('/«block-' . $executionId . '-([0-9]+)»/iU',