summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2017-08-17 15:01:50 +0200
committerLukas Reschke <lukas@statuscode.ch>2017-08-17 15:01:50 +0200
commitc016b01bf91e201d58d7196c24cab4a95b66f219 (patch)
tree75d7a5d38becda041fd88dfe7157949bcb4b21d4 /lib/private
parente37cf2d6f0d32a07ccb6b61cb522725820879eee (diff)
downloadnextcloud-server-c016b01bf91e201d58d7196c24cab4a95b66f219.tar.gz
nextcloud-server-c016b01bf91e201d58d7196c24cab4a95b66f219.zip
Ensure log message is UTF-8 encoded
PHP's json_encode only accept proper UTF-8 strings, loop over all elements to ensure that they are properly UTF-8 compliant or convert them manually. Without this somebody passing an invalid User Agent may make json_encode return false which will get logged as empty newline. Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Log/File.php13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/private/Log/File.php b/lib/private/Log/File.php
index 97ec5012b1f..c6677dd528d 100644
--- a/lib/private/Log/File.php
+++ b/lib/private/Log/File.php
@@ -117,7 +117,18 @@ class File {
'userAgent',
'version'
);
- $entry = json_encode($entry);
+ // PHP's json_encode only accept proper UTF-8 strings, loop over all
+ // elements to ensure that they are properly UTF-8 compliant or convert
+ // them manually.
+ foreach($entry as $key => $value) {
+ if(is_string($value)) {
+ $testEncode = json_encode($value);
+ if($testEncode === false) {
+ $entry[$key] = utf8_encode($value);
+ }
+ }
+ }
+ $entry = json_encode($entry, JSON_PARTIAL_OUTPUT_ON_ERROR);
$handle = @fopen(self::$logFile, 'a');
if ((fileperms(self::$logFile) & 0777) != 0640) {
@chmod(self::$logFile, 0640);