mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-09 12:02:24 +09:00
Prevent function arguments from being exposed in the error log
Also: Produce backtrace when a regular error occurs Also: Remove unnecessary check for DEBUG_BACKTRACE_IGNORE_ARGS (This is not necessary in PHP > 5.3.6)
This commit is contained in:
parent
7484b67b3a
commit
6791208ae1
3 changed files with 26 additions and 10 deletions
|
|
@ -371,7 +371,7 @@ class DB
|
||||||
|
|
||||||
if (config('debug.enabled') && in_array('queries', config('debug.display_content')))
|
if (config('debug.enabled') && in_array('queries', config('debug.display_content')))
|
||||||
{
|
{
|
||||||
$bt = defined('DEBUG_BACKTRACE_IGNORE_ARGS') ? debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) : debug_backtrace();
|
$bt = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||||
foreach($bt as $no => $call)
|
foreach($bt as $no => $call)
|
||||||
{
|
{
|
||||||
if($call['function'] == 'executeQuery' || $call['function'] == 'executeQueryArray')
|
if($call['function'] == 'executeQuery' || $call['function'] == 'executeQueryArray')
|
||||||
|
|
|
||||||
|
|
@ -401,7 +401,7 @@ class FileHandler
|
||||||
|
|
||||||
if (config('debug.enabled') && in_array('slow_remote_requests', config('debug.display_content')))
|
if (config('debug.enabled') && in_array('slow_remote_requests', config('debug.display_content')))
|
||||||
{
|
{
|
||||||
$bt = defined('DEBUG_BACKTRACE_IGNORE_ARGS') ? debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) : debug_backtrace();
|
$bt = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||||
foreach($bt as $no => $call)
|
foreach($bt as $no => $call)
|
||||||
{
|
{
|
||||||
if(strncasecmp($call['function'], 'getRemote', 9) === 0)
|
if(strncasecmp($call['function'], 'getRemote', 9) === 0)
|
||||||
|
|
|
||||||
|
|
@ -148,8 +148,7 @@ class Debug
|
||||||
public static function addEntry($message)
|
public static function addEntry($message)
|
||||||
{
|
{
|
||||||
// Get the backtrace.
|
// Get the backtrace.
|
||||||
$backtrace_args = defined('\DEBUG_BACKTRACE_IGNORE_ARGS') ? \DEBUG_BACKTRACE_IGNORE_ARGS : 0;
|
$backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||||
$backtrace = debug_backtrace($backtrace_args);
|
|
||||||
if (count($backtrace) > 1 && $backtrace[1]['function'] === 'debugPrint' && !$backtrace[1]['class'])
|
if (count($backtrace) > 1 && $backtrace[1]['function'] === 'debugPrint' && !$backtrace[1]['class'])
|
||||||
{
|
{
|
||||||
array_shift($backtrace);
|
array_shift($backtrace);
|
||||||
|
|
@ -203,8 +202,7 @@ class Debug
|
||||||
), $errstr);
|
), $errstr);
|
||||||
|
|
||||||
// Get the backtrace.
|
// Get the backtrace.
|
||||||
$backtrace_args = defined('\DEBUG_BACKTRACE_IGNORE_ARGS') ? \DEBUG_BACKTRACE_IGNORE_ARGS : 0;
|
$backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||||
$backtrace = debug_backtrace($backtrace_args);
|
|
||||||
|
|
||||||
// Prepare the error entry.
|
// Prepare the error entry.
|
||||||
self::$_errors[] = $errinfo = (object)array(
|
self::$_errors[] = $errinfo = (object)array(
|
||||||
|
|
@ -219,9 +217,8 @@ class Debug
|
||||||
// Add the entry to the error log.
|
// Add the entry to the error log.
|
||||||
if (self::$write_to_error_log)
|
if (self::$write_to_error_log)
|
||||||
{
|
{
|
||||||
$log_entry = str_replace("\0", '', sprintf('PHP %s: %s in %s on line %d',
|
$log_entry = strtr(sprintf('PHP %s: %s in %s on line %d', $errinfo->type, $errstr, $errfile, intval($errline)), "\0\r\n\t\v\e\f", ' ');
|
||||||
$errinfo->type, $errstr, $errfile, intval($errline)));
|
error_log($log_entry . \PHP_EOL . self::formatBacktrace($backtrace));
|
||||||
error_log($log_entry);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -374,7 +371,7 @@ class Debug
|
||||||
$log_entry = str_replace("\0", '', sprintf('%s #%d "%s" in %s on line %d',
|
$log_entry = str_replace("\0", '', sprintf('%s #%d "%s" in %s on line %d',
|
||||||
get_class($e), $e->getCode(), $e->getMessage(), $errfile, $e->getLine()));
|
get_class($e), $e->getCode(), $e->getMessage(), $errfile, $e->getLine()));
|
||||||
}
|
}
|
||||||
error_log('PHP Exception: ' . $log_entry . "\n" . str_replace("\0", '', $e->getTraceAsString()));
|
error_log('PHP Exception: ' . $log_entry . \PHP_EOL . self::formatBacktrace($e->getTrace()));
|
||||||
|
|
||||||
// Display the error screen.
|
// Display the error screen.
|
||||||
self::displayErrorScreen($log_entry);
|
self::displayErrorScreen($log_entry);
|
||||||
|
|
@ -407,6 +404,25 @@ class Debug
|
||||||
self::displayErrorScreen($log_entry);
|
self::displayErrorScreen($log_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a backtrace for error logging.
|
||||||
|
*/
|
||||||
|
public static function formatBacktrace($backtrace)
|
||||||
|
{
|
||||||
|
$result = array();
|
||||||
|
foreach ($backtrace as $step)
|
||||||
|
{
|
||||||
|
$stepstr = '#' . count($result) . ' ';
|
||||||
|
$stepstr .= $step['file'] . '(' . $step['line'] . ')';
|
||||||
|
if ($step['function'])
|
||||||
|
{
|
||||||
|
$stepstr .= ': ' . ($step['type'] ? ($step['class'] . $step['type'] . $step['function']) : $step['function']) . '()';
|
||||||
|
}
|
||||||
|
$result[] = strtr($stepstr, "\0\r\n\t\v\e\f", ' ');
|
||||||
|
}
|
||||||
|
return implode(\PHP_EOL, $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translate filenames.
|
* Translate filenames.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue