Commit 5327d19d authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(legacy, crashreporter) limit presentation and upload size of PHP_errors.log...

(legacy, crashreporter) limit presentation and upload size of PHP_errors.log to 1MB, closes https://github.com/opnsense/core/issues/768

(cherry picked from commit 907b786c)
parent bef651db
...@@ -104,7 +104,11 @@ if (isset($_POST['Submit'])) { ...@@ -104,7 +104,11 @@ if (isset($_POST['Submit'])) {
$crash_report_header .= "Description\n\n{$desc}"; $crash_report_header .= "Description\n\n{$desc}";
} }
file_put_contents('/var/crash/crashreport_header.txt', $crash_report_header); 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'); @copy('/var/run/dmesg.boot', '/var/crash/dmesg.boot');
exec('/usr/bin/gzip /var/crash/*'); exec('/usr/bin/gzip /var/crash/*');
$files_to_upload = glob('/var/crash/*'); $files_to_upload = glob('/var/crash/*');
...@@ -132,10 +136,26 @@ $email = isset($config['system']['contact_email']) ? $config['system']['contact_ ...@@ -132,10 +136,26 @@ $email = isset($config['system']['contact_email']) ? $config['system']['contact_
if ($has_crashed) { if ($has_crashed) {
$crash_files = glob("/var/crash/*"); $crash_files = glob("/var/crash/*");
$crash_reports['System Information'] = trim($crash_report_header); $crash_reports['System Information'] = trim($crash_report_header);
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'); $php_errors = @file_get_contents('/tmp/PHP_errors.log');
}
if (!empty($php_errors)) { if (!empty($php_errors)) {
$crash_reports['PHP Errors'] = trim($php_errors); $crash_reports['PHP Errors'] = trim($php_errors);
} }
}
$dmesg_boot = @file_get_contents('/var/run/dmesg.boot'); $dmesg_boot = @file_get_contents('/var/run/dmesg.boot');
if (!empty($dmesg_boot)) { if (!empty($dmesg_boot)) {
$crash_reports['dmesg.boot'] = trim($dmesg_boot); $crash_reports['dmesg.boot'] = trim($dmesg_boot);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment