diff --git a/Zend/tests/type_coercion/gh22112.phpt b/Zend/tests/type_coercion/gh22112.phpt new file mode 100644 index 000000000000..84fdc393a828 --- /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 (Exception $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 538c02f0395e..e874c4a5bbd7 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -537,6 +537,9 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_bool_weak(const zval *arg, bool *dest return 0; } *dest = zend_is_true(arg); + if (UNEXPECTED(EG(exception))) { + return 0; + } } else { return 0; } @@ -762,6 +765,9 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, zend_string **des return 0; } convert_to_string(arg); + if (UNEXPECTED(EG(exception))) { + return 0; + } *dest = Z_STR_P(arg); } else if (UNEXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) { zend_object *zobj = Z_OBJ_P(arg);