diff --git a/Zend/tests/bug60738.phpt b/Zend/tests/bug60738.phpt new file mode 100644 index 0000000000000..e4080715ec72a --- /dev/null +++ b/Zend/tests/bug60738.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #60738 Allow 'set_error_handler' to handle NULL +--FILE-- + +--EXPECTF-- +NULL +Intercepted error! +object(Closure)#1 (0) { +} + +Notice: Error! in %s on line %d diff --git a/Zend/tests/bug60738_variation.phpt b/Zend/tests/bug60738_variation.phpt new file mode 100644 index 0000000000000..d7cf00ecdbc48 --- /dev/null +++ b/Zend/tests/bug60738_variation.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug #60738 Allow 'set_error_handler' to handle NULL +--FILE-- + +--EXPECTF-- +NULL +object(Closure)#1 (0) { +} + +Fatal error: Uncaught exception 'Exception' with message 'Exception!' in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d + diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 8d39a31ad0cd1..ab79ec14f3bdd 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1413,7 +1413,6 @@ ZEND_FUNCTION(trigger_error) ZEND_FUNCTION(set_error_handler) { zval *error_handler; - zend_bool had_orig_error_handler=0; char *error_handler_name = NULL; long error_type = E_ALL | E_STRICT; @@ -1421,38 +1420,31 @@ ZEND_FUNCTION(set_error_handler) return; } - if (!zend_is_callable(error_handler, 0, &error_handler_name TSRMLS_CC)) { - zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback", - get_active_function_name(TSRMLS_C), error_handler_name?error_handler_name:"unknown"); + if (Z_TYPE_P(error_handler) != IS_NULL) { /* NULL == unset */ + if (!zend_is_callable(error_handler, 0, &error_handler_name TSRMLS_CC)) { + zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback", + get_active_function_name(TSRMLS_C), error_handler_name?error_handler_name:"unknown"); + efree(error_handler_name); + return; + } efree(error_handler_name); - return; } - efree(error_handler_name); if (EG(user_error_handler)) { - had_orig_error_handler = 1; - *return_value = *EG(user_error_handler); - zval_copy_ctor(return_value); - INIT_PZVAL(return_value); + RETVAL_ZVAL(EG(user_error_handler), 1, 0); + zend_stack_push(&EG(user_error_handlers_error_reporting), &EG(user_error_handler_error_reporting), sizeof(EG(user_error_handler_error_reporting))); zend_ptr_stack_push(&EG(user_error_handlers), EG(user_error_handler)); } - ALLOC_ZVAL(EG(user_error_handler)); - if (!zend_is_true(error_handler)) { /* unset user-defined handler */ - FREE_ZVAL(EG(user_error_handler)); + if (Z_TYPE_P(error_handler) == IS_NULL) { /* unset user-defined handler */ EG(user_error_handler) = NULL; - RETURN_TRUE; + return; } + ALLOC_ZVAL(EG(user_error_handler)); + MAKE_COPY_ZVAL(&error_handler, EG(user_error_handler)); EG(user_error_handler_error_reporting) = (int)error_type; - *EG(user_error_handler) = *error_handler; - zval_copy_ctor(EG(user_error_handler)); - INIT_PZVAL(EG(user_error_handler)); - - if (!had_orig_error_handler) { - RETURN_NULL(); - } } /* }}} */ @@ -1486,7 +1478,6 @@ ZEND_FUNCTION(set_exception_handler) { zval *exception_handler; char *exception_handler_name = NULL; - zend_bool had_orig_exception_handler=0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &exception_handler) == FAILURE) { return; @@ -1503,24 +1494,18 @@ ZEND_FUNCTION(set_exception_handler) } if (EG(user_exception_handler)) { - had_orig_exception_handler = 1; - *return_value = *EG(user_exception_handler); - zval_copy_ctor(return_value); + RETVAL_ZVAL(EG(user_exception_handler), 1, 0); + zend_ptr_stack_push(&EG(user_exception_handlers), EG(user_exception_handler)); } - ALLOC_ZVAL(EG(user_exception_handler)); if (Z_TYPE_P(exception_handler) == IS_NULL) { /* unset user-defined handler */ - FREE_ZVAL(EG(user_exception_handler)); EG(user_exception_handler) = NULL; - RETURN_TRUE; + return; } + ALLOC_ZVAL(EG(user_exception_handler)); MAKE_COPY_ZVAL(&exception_handler, EG(user_exception_handler)) - - if (!had_orig_exception_handler) { - RETURN_NULL(); - } } /* }}} */