Skip to content

Commit 45210b4

Browse files
committed
Fix segfault when calling from/tryFrom on empty enum
1 parent 50a3cb7 commit 45210b4

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Zend/tests/enum/empty-from.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Empty enum with from/tryFrom doens't segfault
3+
--FILE--
4+
<?php
5+
6+
enum A: string {}
7+
8+
var_dump(A::tryFrom('B'));
9+
10+
?>
11+
--EXPECT--
12+
NULL

Zend/zend_enum.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ ZEND_API zend_result zend_enum_get_case_by_value(zend_object **result, zend_clas
281281
return FAILURE;
282282
}
283283
}
284+
if (!ce->backed_enum_table) {
285+
goto not_found;
286+
}
284287

285288
zval *case_name_zv;
286289
if (ce->enum_backing_type == IS_LONG) {
@@ -292,6 +295,7 @@ ZEND_API zend_result zend_enum_get_case_by_value(zend_object **result, zend_clas
292295
}
293296

294297
if (case_name_zv == NULL) {
298+
not_found:
295299
if (try) {
296300
*result = NULL;
297301
return SUCCESS;

0 commit comments

Comments
 (0)