Skip to content

Commit bc42179

Browse files
committed
Fix GH-10914: OPCache with Enum and Callback functions results in segmentation fault
See linked issue for analysis. Closes GH-11675.
1 parent 6b87e08 commit bc42179

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ PHP NEWS
4141
. Fix GH-11300 (license issue: restricted unicode license headers).
4242
(nielsdos)
4343

44+
- Opcache:
45+
. Fixed bug GH-10914 (OPCache with Enum and Callback functions results in
46+
segmentation fault). (nielsdos)
47+
4448
- PCNTL:
4549
. Fixed bug GH-11498 (SIGCHLD is not always returned from proc_open).
4650
(nielsdos)

ext/opcache/tests/gh10914.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-10914 (OPCache with Enum and Callback functions results in segmentation fault)
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.protect_memory=1
7+
opcache.preload={PWD}/preload_gh10914.inc
8+
--EXTENSIONS--
9+
opcache
10+
--SKIPIF--
11+
<?php
12+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
13+
?>
14+
--FILE--
15+
<?php
16+
$x = new ReflectionEnum(ExampleEnum::class);
17+
var_dump($x->getCases()[0]->getValue());
18+
var_dump($x->getCases()[0]->getBackingValue());
19+
var_dump($x->getCase('FIRST')->getValue());
20+
var_dump($x->getCase('FIRST')->getBackingValue());
21+
?>
22+
--EXPECT--
23+
enum(ExampleEnum::FIRST)
24+
string(4) "AAAb"
25+
enum(ExampleEnum::FIRST)
26+
string(4) "AAAb"

ext/opcache/tests/preload_gh10914.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
enum ExampleEnum: string
3+
{
4+
case FIRST = "AAA"."b";
5+
}

ext/reflection/php_reflection.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6798,7 +6798,7 @@ ZEND_METHOD(ReflectionEnum, getCase)
67986798

67996799
GET_REFLECTION_OBJECT_PTR(ce);
68006800

6801-
zend_class_constant *constant = zend_hash_find_ptr(&ce->constants_table, name);
6801+
zend_class_constant *constant = zend_hash_find_ptr(CE_CONSTANTS_TABLE(ce), name);
68026802
if (constant == NULL) {
68036803
zend_throw_exception_ex(reflection_exception_ptr, 0, "Case %s::%s does not exist", ZSTR_VAL(ce->name), ZSTR_VAL(name));
68046804
RETURN_THROWS();
@@ -6825,7 +6825,7 @@ ZEND_METHOD(ReflectionEnum, getCases)
68256825
GET_REFLECTION_OBJECT_PTR(ce);
68266826

68276827
array_init(return_value);
6828-
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->constants_table, name, constant) {
6828+
ZEND_HASH_FOREACH_STR_KEY_PTR(CE_CONSTANTS_TABLE(ce), name, constant) {
68296829
if (ZEND_CLASS_CONST_FLAGS(constant) & ZEND_CLASS_CONST_IS_CASE) {
68306830
zval class_const;
68316831
reflection_enum_case_factory(ce, name, constant, &class_const);

0 commit comments

Comments
 (0)