diff --git a/NEWS b/NEWS index 30afb9e12381..e90268ccc81b 100644 --- a/NEWS +++ b/NEWS @@ -41,6 +41,8 @@ PHP NEWS . Fixed bug GH-25313 (Assertion !EG(exception) in ZEND_FE_FREE when unpacking a generator into a by-ref parameter throws). (ndossche) . Fix OSS-Fuzz #588264417. (ndossche) + . Fixed bug GH-24701 (Use-after-free on typed trait constants during + opcache preload). (sanklamm, lazerg) - Curl: . Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire) diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index 6d702b67a22d..e97fb42ffc2f 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -2848,6 +2848,7 @@ static void zend_do_traits_constant_binding(zend_class_entry *ce, zend_class_ent Z_TRY_ADDREF(constant->value); constant->doc_comment = constant->doc_comment ? zend_string_copy(constant->doc_comment) : NULL; + zend_type_copy_ctor(&constant->type, /* use_arena */ true, /* persistent */ false); if (constant->attributes && (!(GC_FLAGS(constant->attributes) & IS_ARRAY_IMMUTABLE))) { GC_ADDREF(constant->attributes); } diff --git a/ext/opcache/tests/gh24701.phpt b/ext/opcache/tests/gh24701.phpt new file mode 100644 index 000000000000..c3136fb046a9 --- /dev/null +++ b/ext/opcache/tests/gh24701.phpt @@ -0,0 +1,21 @@ +--TEST-- +GH-24701 (Use-after-free on typed trait constants during opcache preload) +--EXTENSIONS-- +opcache +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.optimization_level=-1 +opcache.preload={PWD}/preload_gh24701.inc +--SKIPIF-- + +--FILE-- + +--EXPECT-- +enum(E::A) +enum(F::B) diff --git a/ext/opcache/tests/preload_gh24701.inc b/ext/opcache/tests/preload_gh24701.inc new file mode 100644 index 000000000000..ebd9039af1f4 --- /dev/null +++ b/ext/opcache/tests/preload_gh24701.inc @@ -0,0 +1,21 @@ +