Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Zend/tests/type_coercion/gh22112.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
GH-22112 (Assertion failure when error handler throws during NaN to bool/string coercion at function entry)
--FILE--
<?php

set_error_handler(function ($errno, $errstr) {
throw new RuntimeException($errstr);
});

function take_bool(bool $v) {
echo "take_bool entered\n";
}

function take_string(string $v) {
echo "take_string entered\n";
}

$nan = fdiv(0, 0);

try {
take_bool($nan);
} catch (RuntimeException $e) {
echo "bool: ", $e->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
9 changes: 8 additions & 1 deletion Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
Loading