Use JSON to encode the stack trace inside the log files
authorTim Düsterhus <duesterhus@woltlab.com>
Sun, 21 Aug 2016 14:01:09 +0000 (16:01 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Sun, 21 Aug 2016 14:03:37 +0000 (16:03 +0200)
As newlines are invalid inside JSON we can omit the base64_encode'ing
and improve security as well (see bf68991d1d97f635a9c2ae52fec685212cda75d5).

wcfsetup/install/files/lib/acp/page/ExceptionLogViewPage.class.php
wcfsetup/install/files/lib/core.functions.php

index bcabb51d641488ec466dc4991261dbe66209bd7c..bff620d2856cdc7ef9e9816c225423f90040b02a 100644 (file)
@@ -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<code>\d+)\s*\n".
 "File: (?P<file>.*?) \((?P<line>\d+)\)\s*\n".
 "Extra Information: (?P<information>(?:-|[a-zA-Z0-9+/]+={0,2}))\s*\n".
-"Stack Trace: (?P<stack>[a-zA-Z0-9+/]+={0,2})", Regex::DOT_ALL);
+"Stack Trace: (?P<stack>\[[^\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());
index 04959d78b304be571639e1103b239b5b5dc86cad..ae481d26d027e765a1228662348c2e9c4c84da4f 100644 (file)
@@ -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());