Skip to content

Commit cb22758

Browse files
twoseGirgias
authored andcommitted
Fix BC break of zend_throw_exception
This also fixes a SegFault Closes GH-5670
1 parent aa9b0cc commit cb22758

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Zend/zend_exceptions.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,9 +851,11 @@ static zend_object *zend_throw_exception_zstr(zend_class_entry *exception_ce, ze
851851

852852
ZEND_API ZEND_COLD zend_object *zend_throw_exception(zend_class_entry *exception_ce, const char *message, zend_long code) /* {{{ */
853853
{
854-
zend_string *msg_str = zend_string_init(message, strlen(message), 0);
854+
zend_string *msg_str = message ? zend_string_init(message, strlen(message), 0) : NULL;
855855
zend_object *ex = zend_throw_exception_zstr(exception_ce, msg_str, code);
856-
zend_string_release(msg_str);
856+
if (msg_str) {
857+
zend_string_release(msg_str);
858+
}
857859
return ex;
858860
}
859861
/* }}} */
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
zend_throw_exception with NULL message
3+
--FILE--
4+
<?php
5+
assert_options(ASSERT_EXCEPTION, true);
6+
try {
7+
$assert = 'assert';
8+
$assert(false);
9+
} catch (AssertionError $assertionError) {
10+
echo 'Done' . PHP_EOL;
11+
}
12+
?>
13+
--EXPECT--
14+
Done

0 commit comments

Comments
 (0)