diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2021-08-05 19:01:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-05 19:01:38 +0200 |
commit | d65a35ed3ad699fab23578b77c79fa50c2494ab9 (patch) | |
tree | 1b098fa6b8848ec29d446eb5619063faa310eb30 | |
parent | fc4e1d3c42f80798115775645d8dd40696ac6acc (diff) | |
parent | b235a854d3d78d0aaf80b6b3920175c5b8d90c1d (diff) | |
download | nextcloud-server-d65a35ed3ad699fab23578b77c79fa50c2494ab9.tar.gz nextcloud-server-d65a35ed3ad699fab23578b77c79fa50c2494ab9.zip |
Merge pull request #28324 from nextcloud/bugfix/noid/avoid-stack-depth-exceed
-rw-r--r-- | lib/private/Log/ExceptionSerializer.php | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/private/Log/ExceptionSerializer.php b/lib/private/Log/ExceptionSerializer.php index a943efd0084..dab134b26a4 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)) { - $data = get_object_vars($arg); - $data['__class__'] = get_class($arg); - return array_map([$this, 'encodeArg'], $data); + if ($nestingLevel === 0) { + return [ + '__class__' => get_class($arg), + '__properties__' => 'Encoding skipped as the maximum nesting level was reached', + ]; + } + + $objectInfo = [ '__class__' => get_class($arg) ]; + $objectVars = get_object_vars($arg); + return array_map(function ($arg) use ($nestingLevel) { + return $this->encodeArg($arg, $nestingLevel - 1); + }, array_merge($objectInfo, $objectVars)); } 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; |