Skip to content
Open
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 Exception($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 (Exception $e) {
echo "bool: ", $e->getMessage(), "\n";
}

try {
take_string($nan);
} catch (Exception $e) {
echo "string: ", $e->getMessage(), "\n";
}
Comment on lines +20 to +30
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try {
take_bool($nan);
} catch (RuntimeException $e) {
echo "bool: ", $e->getMessage(), "\n";
}
try {
take_string($nan);
} catch (RuntimeException $e) {
echo "string: ", $e->getMessage(), "\n";
}
try {
take_bool($nan);
} catch (Exception $e) {
echo "bool: ", $e->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
6 changes: 6 additions & 0 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down