Fix BC break of zend_throw_exception

This also fixes a SegFault

Closes GH-5670
This commit is contained in:
twosee 2020-06-06 14:47:39 +08:00 committed by George Peter Banyard
parent aa9b0ccda8
commit cb2275866d
2 changed files with 18 additions and 2 deletions

View file

@ -851,9 +851,11 @@ static zend_object *zend_throw_exception_zstr(zend_class_entry *exception_ce, ze
ZEND_API ZEND_COLD zend_object *zend_throw_exception(zend_class_entry *exception_ce, const char *message, zend_long code) /* {{{ */ ZEND_API ZEND_COLD zend_object *zend_throw_exception(zend_class_entry *exception_ce, const char *message, zend_long code) /* {{{ */
{ {
zend_string *msg_str = zend_string_init(message, strlen(message), 0); zend_string *msg_str = message ? zend_string_init(message, strlen(message), 0) : NULL;
zend_object *ex = zend_throw_exception_zstr(exception_ce, msg_str, code); zend_object *ex = zend_throw_exception_zstr(exception_ce, msg_str, code);
zend_string_release(msg_str); if (msg_str) {
zend_string_release(msg_str);
}
return ex; return ex;
} }
/* }}} */ /* }}} */

View file

@ -0,0 +1,14 @@
--TEST--
zend_throw_exception with NULL message
--FILE--
<?php
assert_options(ASSERT_EXCEPTION, true);
try {
$assert = 'assert';
$assert(false);
} catch (AssertionError $assertionError) {
echo 'Done' . PHP_EOL;
}
?>
--EXPECT--
Done