From 950de74d1da49a95f97423bc6add1aa9216db1dd Mon Sep 17 00:00:00 2001 From: Julius Härtl Date: Thu, 5 Aug 2021 14:58:03 +0200 Subject: Set a maximum level of encoding nested arguments of exception traces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will make sure that nested objects or arrays do not cause exceeding the maximum nesting level of functions when parsing arguments of an exception trace Signed-off-by: Julius Härtl --- lib/private/Log/ExceptionSerializer.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/private/Log/ExceptionSerializer.php b/lib/private/Log/ExceptionSerializer.php index a943efd0084..97541097451 100644 --- a/lib/private/Log/ExceptionSerializer.php +++ b/lib/private/Log/ExceptionSerializer.php @@ -228,14 +228,27 @@ class ExceptionSerializer { }, $filteredTrace); } - private function encodeArg($arg) { + private function encodeArg($arg, $nestingLevel = 5) { if (is_object($arg)) { + if ($nestingLevel === 0) { + return [ + '__class__' => get_class($arg), + '__properties__' => 'Encoding skipped as the maximum nesting level was reached', + ]; + } + $data = get_object_vars($arg); $data['__class__'] = get_class($arg); - return array_map([$this, 'encodeArg'], $data); + return array_map(function ($arg) use ($nestingLevel) { + return $this->encodeArg($arg, $nestingLevel - 1); + }, $data); } if (is_array($arg)) { + if ($nestingLevel === 0) { + return ['Encoding skipped as the maximum nesting level was reached']; + } + // Only log the first 5 elements of an array unless we are on debug if ((int)$this->systemConfig->getValue('loglevel', 2) !== 0) { $elemCount = count($arg); @@ -244,7 +257,9 @@ class ExceptionSerializer { $arg[] = 'And ' . ($elemCount - 5) . ' more entries, set log level to debug to see all entries'; } } - return array_map([$this, 'encodeArg'], $arg); + return array_map(function ($e) use ($nestingLevel) { + return $this->encodeArg($e, $nestingLevel - 1); + }, $arg); } return $arg; -- cgit v1.2.3 From b235a854d3d78d0aaf80b6b3920175c5b8d90c1d Mon Sep 17 00:00:00 2001 From: Julius Härtl Date: Thu, 5 Aug 2021 15:00:41 +0200 Subject: Always list the class of an object first MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/private/Log/ExceptionSerializer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/private/Log/ExceptionSerializer.php b/lib/private/Log/ExceptionSerializer.php index 97541097451..dab134b26a4 100644 --- a/lib/private/Log/ExceptionSerializer.php +++ b/lib/private/Log/ExceptionSerializer.php @@ -237,11 +237,11 @@ class ExceptionSerializer { ]; } - $data = get_object_vars($arg); - $data['__class__'] = get_class($arg); + $objectInfo = [ '__class__' => get_class($arg) ]; + $objectVars = get_object_vars($arg); return array_map(function ($arg) use ($nestingLevel) { return $this->encodeArg($arg, $nestingLevel - 1); - }, $data); + }, array_merge($objectInfo, $objectVars)); } if (is_array($arg)) { -- cgit v1.2.3