1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-24 20:13:22 +01:00

Merge remote-tracking branch 'github-bantu/ticket/10369' into develop-olympus

* github-bantu/ticket/10369:
  [ticket/10369] Replace root path with "[ROOT]" as per IRC.
  [ticket/10369] Add warning about paths outside of phpBB root not being filtered
  [ticket/10369] Rename filter_errfile() to filter_root_path().
  [ticket/10369] DRY code to remove phpbb path from errfile.
  [ticket/10369] Always include errfile and errline in format_errors().
This commit is contained in:
Nils Adermann 2011-09-18 23:20:45 +02:00
commit 94fead702a
3 changed files with 67 additions and 8 deletions

View File

@ -49,13 +49,15 @@ class phpbb_error_collector
{
$text .= "<br />\n";
}
list($errno, $msg_text, $errfile, $errline) = $error;
$text .= "Errno $errno: $msg_text";
if (defined('DEBUG_EXTRA') || defined('IN_INSTALL'))
{
$text .= " at $errfile line $errline";
}
// Prevent leakage of local path to phpBB install
$errfile = phpbb_filter_root_path($errfile);
$text .= "Errno $errno: $msg_text at $errfile line $errline";
}
return $text;
}
}

View File

@ -3816,9 +3816,8 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
if (strpos($errfile, 'cache') === false && strpos($errfile, 'template.') === false)
{
// remove complete path to installation, with the risk of changing backslashes meant to be there
$errfile = str_replace(array(phpbb_realpath($phpbb_root_path), '\\'), array('', '/'), $errfile);
$msg_text = str_replace(array(phpbb_realpath($phpbb_root_path), '\\'), array('', '/'), $msg_text);
$errfile = phpbb_filter_root_path($errfile);
$msg_text = phpbb_filter_root_path($msg_text);
$error_name = ($errno === E_WARNING) ? 'PHP Warning' : 'PHP Notice';
echo '<b>[phpBB Debug] ' . $error_name . '</b>: in file <b>' . $errfile . '</b> on line <b>' . $errline . '</b>: <b>' . $msg_text . '</b><br />' . "\n";
@ -3996,6 +3995,29 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
return false;
}
/**
* Removes absolute path to phpBB root directory from error messages
* and converts backslashes to forward slashes.
*
* @param string $errfile Absolute file path
* (e.g. /var/www/phpbb3/phpBB/includes/functions.php)
* Please note that if $errfile is outside of the phpBB root,
* the root path will not be found and can not be filtered.
* @return string Relative file path
* (e.g. /includes/functions.php)
*/
function phpbb_filter_root_path($errfile)
{
static $root_path;
if (empty($root_path))
{
$root_path = phpbb_realpath(dirname(__FILE__) . '/../');
}
return str_replace(array($root_path, '\\'), array('[ROOT]', '/'), $errfile);
}
/**
* Queries the session table to get information about online guests
* @param int $item_id Limits the search to the item with this id

View File

@ -0,0 +1,35 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
require_once dirname(__FILE__) . '/../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../phpBB/includes/error_collector.php';
class phpbb_error_collector_test extends phpbb_test_case
{
public function test_collection()
{
$collector = new phpbb_error_collector;
$collector->install();
// Cause a warning
1/0; $line = __LINE__;
$collector->uninstall();
list($errno, $msg_text, $errfile, $errline) = $collector->errors[0];
$error_contents = $collector->format_errors();
$this->assertEquals($errno, 2);
// Unfortunately $error_contents will contain the full path here,
// because the tests directory is outside of phpbb root path.
$this->assertStringStartsWith('Errno 2: Division by zero at ', $error_contents);
$this->assertStringEndsWith(" line $line", $error_contents);
}
}