From b29dc146b9311c14186c14bcb1c8ae5288b65d73 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 6 Sep 2012 11:26:40 +0400 Subject: [PATCH] - Fixed bug #61767 (Shutdown functions not called in certain error situation) - Fixed bug #60909 (custom error handler throwing Exception + fatal error = no shutdown function) --- NEWS | 6 +++++- Zend/tests/bug51394.phpt | 6 ++++++ Zend/tests/bug60909_1.phpt | 24 ++++++++++++++++++++++++ Zend/tests/bug60909_2.phpt | 20 ++++++++++++++++++++ Zend/tests/bug61767.phpt | 34 ++++++++++++++++++++++++++++++++++ Zend/zend.c | 23 +++++++++++++++++++++++ Zend/zend_object_handlers.c | 1 + 7 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/bug60909_1.phpt create mode 100644 Zend/tests/bug60909_2.phpt create mode 100644 Zend/tests/bug61767.phpt diff --git a/NEWS b/NEWS index a0e8a68642..a1ff9b9ffa 100644 --- a/NEWS +++ b/NEWS @@ -13,9 +13,13 @@ PHP NEWS . Fixed bug #62744 (dangling pointers made by zend_disable_class). (Laruence) . Fixed bug #62716 (munmap() is called with the incorrect length). (slangley@google.com) - . Fixed bug ##62460 (php binaries installed as binary.dSYM). (Reeze Xia) + . Fixed bug #62460 (php binaries installed as binary.dSYM). (Reeze Xia) + . Fixed bug #61767 (Shutdown functions not called in certain error + situation). (Dmitry) . Fixed bug #60194 (--with-zend-multibyte and --enable-debug reports LEAK with run-test.php). (Laruence) + . Fixed bug #60909 (custom error handler throwing Exception + fatal error + = no shutdown function). (Dmitry) - CURL: . Fixed bug #62839 (curl_copy_handle segfault with CURLOPT_FILE). (Pierrick) diff --git a/Zend/tests/bug51394.phpt b/Zend/tests/bug51394.phpt index 537574c9d5..406de13a9b 100644 --- a/Zend/tests/bug51394.phpt +++ b/Zend/tests/bug51394.phpt @@ -13,4 +13,10 @@ function eh() set_error_handler("eh"); $a = $empty($b); --EXPECTF-- +Warning: Uncaught exception 'Exception' with message 'error!' in %sbug51394.php:4 +Stack trace: +#0 %sbug51394.php(9): eh(8, 'Undefined varia...', '%s', 9, Array) +#1 {main} + thrown in %sbug51394.php on line 4 + Fatal error: Function name must be a string in %sbug51394.php on line 9 \ No newline at end of file diff --git a/Zend/tests/bug60909_1.phpt b/Zend/tests/bug60909_1.phpt new file mode 100644 index 0000000000..5150dfc025 --- /dev/null +++ b/Zend/tests/bug60909_1.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #60909 (custom error handler throwing Exception + fatal error = no shutdown function). +--FILE-- +foo(); +--EXPECTF-- +Error handler called (Undefined variable: undefined) + +Warning: Uncaught exception 'ErrorException' with message 'Undefined variable: undefined' in %sbug61767.php:13 +Stack trace: +#0 %sbug61767.php(13): {closure}(8, 'Undefined varia...', '%s', 13, Array) +#1 {main} + thrown in %sbug61767.php on line 13 + +Fatal error: Call to a member function foo() on a non-object in %sbug61767.php on line 13 +Shutting down +Array +( + [type] => 1 + [message] => Call to a member function foo() on a non-object + [file] => %sbug61767.php + [line] => 13 +) diff --git a/Zend/zend.c b/Zend/zend.c index ea32346dae..bd53d55183 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -997,6 +997,29 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */ zend_stack labels_stack; TSRMLS_FETCH(); + /* Report about uncaught exception in case of fatal errors */ + if (EG(exception)) { + switch (type) { + case E_CORE_ERROR: + case E_ERROR: + case E_RECOVERABLE_ERROR: + case E_PARSE: + case E_COMPILE_ERROR: + case E_USER_ERROR: + if (zend_is_executing(TSRMLS_C)) { + error_lineno = zend_get_executed_lineno(TSRMLS_C); + } + zend_exception_error(EG(exception), E_WARNING TSRMLS_CC); + EG(exception) = NULL; + if (zend_is_executing(TSRMLS_C) && EG(opline_ptr)) { + active_opline->lineno = error_lineno; + } + break; + default: + break; + } + } + /* Obtain relevant filename and lineno */ switch (type) { case E_CORE_ERROR: diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 288a5dfc92..eae47d9c5a 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -1272,6 +1272,7 @@ ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int ty if (retval) { zval_ptr_dtor(&retval); } + EG(exception) = NULL; zend_error(E_ERROR, "Method %s::__toString() must not throw an exception", ce->name); return FAILURE; } -- 2.40.0