Skip to content

Commit

Permalink
Merge branch 'QA_4_6'
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Sep 2, 2016
2 parents 761281f + 829d51c commit bfd6a76
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
15 changes: 3 additions & 12 deletions libraries/DatabaseInterface.php
Expand Up @@ -2328,21 +2328,12 @@ public function connect($mode, $server = null)
return false;
}

$error_count = $GLOBALS['error_handler']->countErrors();
// Do not show location and backtrace for connection errors
$error_count = $GLOBALS['error_handler']->setHideLocation(true);
$result = $this->_extension->connect(
$user, $password, $server
);

/* 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
);
}
}
$error_count = $GLOBALS['error_handler']->setHideLocation(false);

if ($result) {
/* Run post connect for user connections */
Expand Down
20 changes: 19 additions & 1 deletion libraries/Error.php
Expand Up @@ -83,6 +83,11 @@ class Error extends Message
*/
protected $backtrace = array();

/**
* Hide location of errors
*/
protected $hide_location = false;

/**
* Constructor
*
Expand Down Expand Up @@ -146,6 +151,18 @@ public static function processBacktrace($backtrace)
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
*
Expand Down Expand Up @@ -441,7 +458,8 @@ public function getDisplay()
*/
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));
}

/**
Expand Down
18 changes: 18 additions & 0 deletions libraries/ErrorHandler.php
Expand Up @@ -23,6 +23,11 @@ class ErrorHandler
*/
protected $errors = array();

/**
* Hide location of errors
*/
protected $hide_location = false;

/**
* Constructor - set PHP error handler
*
Expand Down Expand Up @@ -77,6 +82,18 @@ public function __destruct()
}
}

/**
* Toggles location hiding
*
* @param boolean $hide Whether to hide
*
* @return void
*/
public function setHideLocation($hide)
{
$this->hide_location = $hide;
}

/**
* returns array with all errors
*
Expand Down Expand Up @@ -170,6 +187,7 @@ public function addError($errstr, $errno, $errfile, $errline, $escape = true)
$errfile,
$errline
);
$error->setHideLocation($this->hide_location);

// do not repeat errors
$this->errors[$error->getHash()] = $error;
Expand Down
4 changes: 2 additions & 2 deletions libraries/session.inc.php
Expand Up @@ -88,9 +88,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())
);
}

Expand Down

0 comments on commit bfd6a76

Please sign in to comment.