This also fixes a SegFault
Closes GH-5670
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_string_release(msg_str);
+ if (msg_str) {
+ zend_string_release(msg_str);
+ }
return ex;
}
/* }}} */
--- /dev/null
+--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