From 40f6d8546c0d7b0a7bff80dfd40acb6d26d353e7 Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 15 Nov 2013 16:13:19 +0100 Subject: [PATCH] Make sure we always restore the error handler. Change-Id: I27f5d11ea27f783eda71c2bfdba7e70695f5d53c --- includes/Hooks.php | 3 +++ includes/UserMailer.php | 19 ++++++++++++------- includes/db/DatabaseMysqlBase.php | 1 + includes/db/DatabasePostgres.php | 9 ++++++++- includes/installer/WebInstaller.php | 7 ++++++- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/includes/Hooks.php b/includes/Hooks.php index 396e360dd8..db47d3194e 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -199,6 +199,9 @@ class Hooks { $retval = call_user_func_array( $callback, $hook_args ); } catch ( MWHookException $e ) { $badhookmsg = $e->getMessage(); + } catch ( Exception $e ) { + restore_error_handler(); + throw $e; } restore_error_handler(); wfProfileOut( $func ); diff --git a/includes/UserMailer.php b/includes/UserMailer.php index 8ab10b2d1a..6157f78122 100644 --- a/includes/UserMailer.php +++ b/includes/UserMailer.php @@ -352,14 +352,19 @@ class UserMailer { ini_set( 'html_errors', '0' ); set_error_handler( 'UserMailer::errorHandler' ); - $safeMode = wfIniGetBool( 'safe_mode' ); - - foreach ( $to as $recip ) { - if ( $safeMode ) { - $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers ); - } else { - $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams ); + try { + $safeMode = wfIniGetBool( 'safe_mode' ); + + foreach ( $to as $recip ) { + if ( $safeMode ) { + $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers ); + } else { + $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams ); + } } + } catch ( Exception $e ) { + restore_error_handler(); + throw $e; } restore_error_handler(); diff --git a/includes/db/DatabaseMysqlBase.php b/includes/db/DatabaseMysqlBase.php index 26c9d247d2..cdfa76902a 100644 --- a/includes/db/DatabaseMysqlBase.php +++ b/includes/db/DatabaseMysqlBase.php @@ -76,6 +76,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { } catch ( Exception $ex ) { wfProfileOut( "dbconnect-$server" ); wfProfileOut( __METHOD__ ); + $this->restoreErrorHandler(); throw $ex; } $error = $this->restoreErrorHandler(); diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index e564a162dd..72371a25a8 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -370,7 +370,14 @@ class DatabasePostgres extends DatabaseBase { $this->connectString = $this->makeConnectionString( $connectVars, PGSQL_CONNECT_FORCE_NEW ); $this->close(); $this->installErrorHandler(); - $this->mConn = pg_connect( $this->connectString ); + + try { + $this->mConn = pg_connect( $this->connectString ); + } catch ( Exception $ex ) { + $this->restoreErrorHandler(); + throw $ex; + } + $phpError = $this->restoreErrorHandler(); if ( !$this->mConn ) { diff --git a/includes/installer/WebInstaller.php b/includes/installer/WebInstaller.php index 53cb7dc519..b37e6b37af 100644 --- a/includes/installer/WebInstaller.php +++ b/includes/installer/WebInstaller.php @@ -336,7 +336,12 @@ class WebInstaller extends Installer { $this->phpErrors = array(); set_error_handler( array( $this, 'errorHandler' ) ); - session_start(); + try { + session_start(); + } catch ( Exception $e ) { + restore_error_handler(); + throw $e; + } restore_error_handler(); if ( $this->phpErrors ) { -- 2.20.1