From 907b786ceb468e317267b3ef8a375cb82331e91e Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Wed, 10 Feb 2016 10:04:26 +0100 Subject: [PATCH] (legacy, crashreporter) limit presentation and upload size of PHP_errors.log to 1MB, closes https://github.com/opnsense/core/issues/768 --- src/www/crash_reporter.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/www/crash_reporter.php b/src/www/crash_reporter.php index 767b0b60a..083943abb 100644 --- a/src/www/crash_reporter.php +++ b/src/www/crash_reporter.php @@ -104,7 +104,11 @@ if (isset($_POST['Submit'])) { $crash_report_header .= "Description\n\n{$desc}"; } file_put_contents('/var/crash/crashreport_header.txt', $crash_report_header); - @rename('/tmp/PHP_errors.log', '/var/crash/PHP_errors.log'); + if (file_exists('/tmp/PHP_errors.log')) { + // limit PHP_errors to send to 1MB + exec('/usr/bin/tail -c 1048576 /tmp/PHP_errors.log > /var/crash/PHP_errors.log'); + @unlink('/tmp/PHP_errors.log'); + } @copy('/var/run/dmesg.boot', '/var/crash/dmesg.boot'); exec('/usr/bin/gzip /var/crash/*'); $files_to_upload = glob('/var/crash/*'); @@ -132,9 +136,25 @@ $email = isset($config['system']['contact_email']) ? $config['system']['contact_ if ($has_crashed) { $crash_files = glob("/var/crash/*"); $crash_reports['System Information'] = trim($crash_report_header); - $php_errors = @file_get_contents('/tmp/PHP_errors.log'); - if (!empty($php_errors)) { - $crash_reports['PHP Errors'] = trim($php_errors); + if (file_exists('/tmp/PHP_errors.log')) { + $php_errors_size = @filesize('/tmp/PHP_errors.log'); + $max_php_errors_size = 1048576; // 1MB + // limit reporting for PHP_errors.log to $max_php_errors_size characters + if ($php_errors_size > $max_php_errors_size) { + // if file is to large, only display last $max_php_errors_size characters + $php_errors .= @file_get_contents( + '/tmp/PHP_errors.log', + NULL, + NULL, + ($php_errors_size - $max_php_errors_size), + $max_php_errors_size + ); + } else { + $php_errors = @file_get_contents('/tmp/PHP_errors.log'); + } + if (!empty($php_errors)) { + $crash_reports['PHP Errors'] = trim($php_errors); + } } $dmesg_boot = @file_get_contents('/var/run/dmesg.boot'); if (!empty($dmesg_boot)) {