aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Log
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2021-08-05 14:58:03 +0200
committerJulius Härtl <jus@bitgrid.net>2021-08-05 17:35:52 +0200
commit950de74d1da49a95f97423bc6add1aa9216db1dd (patch)
tree2f1fdda916e1e21c824929e5a18044d5c2a5c54e /lib/private/Log
parentfc4e1d3c42f80798115775645d8dd40696ac6acc (diff)
downloadnextcloud-server-950de74d1da49a95f97423bc6add1aa9216db1dd.tar.gz
nextcloud-server-950de74d1da49a95f97423bc6add1aa9216db1dd.zip
Set a maximum level of encoding nested arguments of exception traces
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 <jus@bitgrid.net>
Diffstat (limited to 'lib/private/Log')
-rw-r--r--lib/private/Log/ExceptionSerializer.php21
1 files 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;