Use zend_throw_unwind_exit() for assert.bail (#6826)

We can use unwind_exit instead of the evil zend_bailout without breaking the original behavior in this way because the original zend_bailout will longjmp out of the executor, so the exception will never be caught and it always triggers the E_ERROR here.
This commit is contained in:
twosee 2021-04-13 15:23:36 +08:00 committed by GitHub
parent b7a298b20c
commit d5456baf52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -7,7 +7,11 @@ assert.exception=1
<?php
define ("XXXXX", 1);
assert(false);
try {
assert(false);
} catch (AssertionError $error) {
echo "Caught\n";
}
?>
--EXPECTHEADERS--

View File

@ -186,15 +186,20 @@ PHP_FUNCTION(assert)
if (ASSERTG(exception)) {
zend_throw_exception(assertion_error_ce, description_str ? ZSTR_VAL(description_str) : NULL, E_ERROR);
if (ASSERTG(bail)) {
/* When bail is turned on, the exception will not be caught. */
zend_exception_error(EG(exception), E_ERROR);
}
} else if (ASSERTG(warning)) {
php_error_docref(NULL, E_WARNING, "%s failed", description_str ? ZSTR_VAL(description_str) : "Assertion failed");
}
if (ASSERTG(bail)) {
zend_bailout();
zend_throw_unwind_exit();
RETURN_THROWS();
} else {
RETURN_FALSE;
}
RETURN_FALSE;
}
/* }}} */