Browse Source

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>
pull/28324/head
Julius Härtl 5 years ago
parent
commit
950de74d1d
No known key found for this signature in database GPG Key ID: 4C614C6ED2CDE6DF
  1. 21
      lib/private/Log/ExceptionSerializer.php

21
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;

Loading…
Cancel
Save