diff --git a/Zend/tests/type_coercion/gh22112.phpt b/Zend/tests/type_coercion/gh22112.phpt new file mode 100644 index 000000000000..864f5313055b --- /dev/null +++ b/Zend/tests/type_coercion/gh22112.phpt @@ -0,0 +1,35 @@ +--TEST-- +GH-22112 (Assertion failure when error handler throws during NaN to bool/string coercion at function entry) +--FILE-- +getMessage(), "\n"; +} + +try { + take_string($nan); +} catch (RuntimeException $e) { + echo "string: ", $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +bool: unexpected NAN value was coerced to bool +string: unexpected NAN value was coerced to string diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 65834adbafff..3063dbb71801 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -515,7 +515,11 @@ ZEND_API zpp_parse_bool_status ZEND_FASTCALL zend_parse_arg_bool_weak(const zval if (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) && !zend_null_arg_deprecated("bool", arg_num)) { return ZPP_PARSE_BOOL_STATUS_ERROR; } - return zend_is_true(arg); + zpp_parse_bool_status result = (zpp_parse_bool_status) zend_is_true(arg); + if (UNEXPECTED(EG(exception))) { + return ZPP_PARSE_BOOL_STATUS_ERROR; + } + return result; } return ZPP_PARSE_BOOL_STATUS_ERROR; } @@ -735,6 +739,9 @@ ZEND_API zend_string* ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, uint32_t return NULL; } convert_to_string(arg); + if (UNEXPECTED(EG(exception))) { + return NULL; + } return Z_STR_P(arg); } else if (UNEXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) { zend_object *zobj = Z_OBJ_P(arg);