diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index e4c3ed5026..600b473687 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -2351,21 +2351,12 @@ class DatabaseInterface $user, $password, $is_controluser = false, $server = null, $auxiliary_connection = false ) { - $error_count = $GLOBALS['error_handler']->countErrors(); + // Do not show location and backtrace for connection errors + $GLOBALS['error_handler']->setHideLocation(true); $result = $this->_extension->connect( $user, $password, $is_controluser, $server, $auxiliary_connection ); - - /* Any errors from connection? */ - if ($GLOBALS['error_handler']->countErrors() > $error_count) { - $errors = $GLOBALS['error_handler']->sliceErrors($error_count); - foreach ($errors as $error) { - trigger_error( - $error->getMessage(), - E_USER_ERROR - ); - } - } + $GLOBALS['error_handler']->setHideLocation(false); if ($result) { if (! $auxiliary_connection && ! $is_controluser) { diff --git a/libraries/Error.php b/libraries/Error.php index 6548877c60..b45afef75a 100644 --- a/libraries/Error.php +++ b/libraries/Error.php @@ -83,6 +83,11 @@ class Error extends Message */ protected $backtrace = array(); + /** + * Hide location of errors + */ + protected $hide_location = false; + /** * Constructor * @@ -146,6 +151,18 @@ class Error extends Message return $result; } + /** + * Toggles location hiding + * + * @param boolean $hide Whether to hide + * + * @return void + */ + public function setHideLocation($hide) + { + $this->hide_location = $hide; + } + /** * sets PMA\libraries\Error::$_backtrace * @@ -441,7 +458,8 @@ class Error extends Message */ public function isUserError() { - return $this->getNumber() & (E_USER_WARNING | E_USER_ERROR | E_USER_NOTICE); + return $this->hide_location || + ($this->getNumber() & (E_USER_WARNING | E_USER_ERROR | E_USER_NOTICE)); } /** diff --git a/libraries/ErrorHandler.php b/libraries/ErrorHandler.php index 8bd408d5a1..0e96f8e026 100644 --- a/libraries/ErrorHandler.php +++ b/libraries/ErrorHandler.php @@ -23,6 +23,11 @@ class ErrorHandler */ protected $errors = array(); + /** + * Hide location of errors + */ + protected $hide_location = false; + /** * Constructor - set PHP error handler * @@ -77,6 +82,18 @@ class ErrorHandler } } + /** + * Toggles location hiding + * + * @param boolean $hide Whether to hide + * + * @return void + */ + public function setHideLocation($hide) + { + $this->hide_location = $hide; + } + /** * returns array with all errors * @@ -170,6 +187,7 @@ class ErrorHandler $errfile, $errline ); + $error->setHideLocation($this->hide_location); // do not repeat errors $this->errors[$error->getHash()] = $error; diff --git a/libraries/session.inc.php b/libraries/session.inc.php index f1e6370df5..71bd614d0a 100644 --- a/libraries/session.inc.php +++ b/libraries/session.inc.php @@ -86,9 +86,9 @@ function PMA_sessionFailed($errors) * will not change in future. */ $messages[] = preg_replace( - '/open(.*, O_RDWR)/', + '/open\(.*, O_RDWR\)/', 'open(SESSION_FILE, O_RDWR)', - $error->getMessage() + htmlspecialchars($error->getMessage()) ); }