From 9006984d5ab7478e9187d14c5ab331057b1af9a4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 18 Sep 2011 22:20:20 +0200 Subject: [ticket/10369] DRY code to remove phpbb path from errfile. PHPBB3-10369 --- phpBB/includes/functions.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 628f8ee123..4c1bfb4360 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -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_errfile($errfile); + $msg_text = phpbb_filter_errfile($msg_text); $error_name = ($errno === E_WARNING) ? 'PHP Warning' : 'PHP Notice'; echo '[phpBB Debug] ' . $error_name . ': in file ' . $errfile . ' on line ' . $errline . ': ' . $msg_text . '
' . "\n"; @@ -3996,6 +3995,27 @@ 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) +* @return string Relative file path +* (e.g. /includes/functions.php) +*/ +function phpbb_filter_errfile($errfile) +{ + static $root_path; + + if (empty($root_path)) + { + $root_path = phpbb_realpath(dirname(__FILE__) . '/../'); + } + + return str_replace(array($root_path, '\\'), array('', '/'), $errfile); +} + /** * Queries the session table to get information about online guests * @param int $item_id Limits the search to the item with this id -- cgit v1.2.1 From 1ad97424a469fe2e36a3c3a616b5e49def292779 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 18 Sep 2011 22:32:25 +0200 Subject: [ticket/10369] Rename filter_errfile() to filter_root_path(). PHPBB3-10369 --- phpBB/includes/functions.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 4c1bfb4360..cd856f55a7 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3816,8 +3816,8 @@ function msg_handler($errno, $msg_text, $errfile, $errline) if (strpos($errfile, 'cache') === false && strpos($errfile, 'template.') === false) { - $errfile = phpbb_filter_errfile($errfile); - $msg_text = phpbb_filter_errfile($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 '[phpBB Debug] ' . $error_name . ': in file ' . $errfile . ' on line ' . $errline . ': ' . $msg_text . '
' . "\n"; @@ -4004,7 +4004,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline) * @return string Relative file path * (e.g. /includes/functions.php) */ -function phpbb_filter_errfile($errfile) +function phpbb_filter_root_path($errfile) { static $root_path; -- cgit v1.2.1 From c8564e6ce98980143c42a67b51b0c8327cfc12b5 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 18 Sep 2011 22:41:02 +0200 Subject: [ticket/10369] Add warning about paths outside of phpBB root not being filtered PHPBB3-10369 --- phpBB/includes/functions.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index cd856f55a7..2e445192ae 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4001,6 +4001,8 @@ function msg_handler($errno, $msg_text, $errfile, $errline) * * @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) */ -- cgit v1.2.1 From 1b390f0b498f1eb977dd62dc06dd5753b0c7ea65 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 18 Sep 2011 23:03:28 +0200 Subject: [ticket/10369] Replace root path with "[ROOT]" as per IRC. PHPBB3-10369 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 2e445192ae..e01bbe36d1 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4015,7 +4015,7 @@ function phpbb_filter_root_path($errfile) $root_path = phpbb_realpath(dirname(__FILE__) . '/../'); } - return str_replace(array($root_path, '\\'), array('', '/'), $errfile); + return str_replace(array($root_path, '\\'), array('[ROOT]', '/'), $errfile); } /** -- cgit v1.2.1