]> granicus.if.org Git - php/commitdiff
Fix BC break of zend_throw_exception
authortwosee <twose@qq.com>
Sat, 6 Jun 2020 06:47:39 +0000 (14:47 +0800)
committerGeorge Peter Banyard <girgias@php.net>
Sat, 6 Jun 2020 15:17:44 +0000 (17:17 +0200)
This also fixes a SegFault

Closes GH-5670

Zend/zend_exceptions.c
tests/lang/zend_throw_exception_001.phpt [new file with mode: 0644]

index 0204e14a58f6a88acbe1c4a5c0b9ae15c4b65ccc..57eb0108210695339b876a915be730d54995b465 100644 (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_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;
 }
 /* }}} */
diff --git a/tests/lang/zend_throw_exception_001.phpt b/tests/lang/zend_throw_exception_001.phpt
new file mode 100644 (file)
index 0000000..c8d3603
--- /dev/null
@@ -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