Skip to content

Commit

Permalink
Gracefully handle early fatal errors in AJAX requests
Browse files Browse the repository at this point in the history
Generate response manually when Response object is not yet ready to be
used but we need AJAX response.

Fixes #13092

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Jun 8, 2017
1 parent e317e48 commit f4ae5f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -11,6 +11,7 @@ phpMyAdmin - ChangeLog
- issue #13362 Fixed loading additional javascripts
- issue #13343 Fixed editing QBE
- issue #13193 Improved documentation on user settings
- issue #13092 Gracefully handle early fatal errors in AJAX requests

4.7.1 (2017-05-25)
- issue #13132 Always execute tracking queries as controluser
Expand Down
19 changes: 10 additions & 9 deletions libraries/core.lib.php
Expand Up @@ -222,17 +222,18 @@ function PMA_fatalError($error_message, $message_args = null) {
}

/*
* Avoid using Response if Config is not yet loaded
* Avoid using Response class as config does not have to be loaded yet
* (this can happen on early fatal error)
*/
if (isset($GLOBALS['Config'])) {
$response = Response::getInstance();
} else {
$response = null;
}
if (! is_null($response) && $response->isAjax()) {
$response->setRequestStatus(false);
$response->addJSON('message', PMA\libraries\Message::error($error_message));
if (! empty($_REQUEST['ajax_request'])) {
// Generate JSON manually
PMA_headerJSON();
echo json_encode(
array(
'success' => false,
'error' => Message::error($error_message)->getDisplay(),
)
);
} else {
$error_message = strtr($error_message, array('<br />' => '[br]'));

Expand Down

0 comments on commit f4ae5f0

Please sign in to comment.