From 72f128c327e8986a1b9671a8359fdcd8107cb40c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 21 Aug 2016 16:01:09 +0200 Subject: [PATCH] Use JSON to encode the stack trace inside the log files As newlines are invalid inside JSON we can omit the base64_encode'ing and improve security as well (see bf68991d1d97f635a9c2ae52fec685212cda75d5). --- .../files/lib/acp/page/ExceptionLogViewPage.class.php | 10 +++------- wcfsetup/install/files/lib/core.functions.php | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/page/ExceptionLogViewPage.class.php b/wcfsetup/install/files/lib/acp/page/ExceptionLogViewPage.class.php index bcabb51d64..bff620d285 100644 --- a/wcfsetup/install/files/lib/acp/page/ExceptionLogViewPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/ExceptionLogViewPage.class.php @@ -8,6 +8,7 @@ use wcf\system\Regex; use wcf\system\WCF; use wcf\util\DirectoryUtil; use wcf\util\StringUtil; +use wcf\util\JSON; /** * Shows the exception log. @@ -147,7 +148,7 @@ class ExceptionLogViewPage extends MultipleLinkPage { "Error Code: (?P\d+)\s*\n". "File: (?P.*?) \((?P\d+)\)\s*\n". "Extra Information: (?P(?:-|[a-zA-Z0-9+/]+={0,2}))\s*\n". -"Stack Trace: (?P[a-zA-Z0-9+/]+={0,2})", Regex::DOT_ALL); +"Stack Trace: (?P\[[^\n]+\])", Regex::DOT_ALL); $isPhp7 = version_compare(PHP_VERSION, '7.0.0') >= 0; foreach ($this->exceptions as $key => $val) { @@ -175,12 +176,7 @@ class ExceptionLogViewPage extends MultipleLinkPage { } } - if ($isPhp7) { - $item['stack'] = unserialize(base64_decode($item['stack']), ['allowed_classes' => false]); - } - else { - $item['stack'] = unserialize(base64_decode($item['stack'])); - } + $item['stack'] = JSON::decode($item['stack']); return $item; }, $chainRegex->getMatches()); diff --git a/wcfsetup/install/files/lib/core.functions.php b/wcfsetup/install/files/lib/core.functions.php index 04959d78b3..ae481d26d0 100644 --- a/wcfsetup/install/files/lib/core.functions.php +++ b/wcfsetup/install/files/lib/core.functions.php @@ -120,7 +120,7 @@ namespace wcf\functions\exception { 'Error Code: '.intval($e->getCode())."\n". 'File: '.str_replace("\n", ' ', $e->getFile()).' ('.$e->getLine().')'."\n". 'Extra Information: '.($e instanceof IExtraInformationException ? base64_encode(serialize($e->getExtraInformation())) : '-')."\n". - 'Stack Trace: '.base64_encode(serialize(array_map(function ($item) { + 'Stack Trace: '.json_encode(array_map(function ($item) { $item['args'] = array_map(function ($item) { switch (gettype($item)) { case 'object': @@ -135,7 +135,7 @@ namespace wcf\functions\exception { }, $item['args']); return $item; - }, sanitizeStacktrace($e, true))))."\n"; + }, sanitizeStacktrace($e, true)))."\n"; } while ($e = $e->getPrevious()); -- 2.20.1