Skip to content

Commit 5fd2a5b

Browse files
committed
Fix handling of unknown class in trait precedence list
Fixes oss-fuzz #31983.
1 parent 89c6118 commit 5fd2a5b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Unknown class in absolute trait precedence reference
3+
--FILE--
4+
<?php
5+
6+
trait T {}
7+
class C {
8+
use T {
9+
WrongClass::method insteadof C;
10+
}
11+
}
12+
13+
?>
14+
--EXPECTF--
15+
Fatal error: Could not find trait WrongClass in %s on line %d

Zend/zend_inheritance.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ static void zend_traits_init_trait_structures(zend_class_entry *ce, zend_class_e
18161816
lc_trait_name = zend_string_tolower(cur_method_ref->class_name);
18171817
trait = zend_hash_find_ptr(EG(class_table), lc_trait_name);
18181818
zend_string_release_ex(lc_trait_name, 0);
1819-
if (!trait && !(trait->ce_flags & ZEND_ACC_LINKED)) {
1819+
if (!trait || !(trait->ce_flags & ZEND_ACC_LINKED)) {
18201820
zend_error_noreturn(E_COMPILE_ERROR, "Could not find trait %s", ZSTR_VAL(cur_method_ref->class_name));
18211821
}
18221822
zend_check_trait_usage(ce, trait, traits);

0 commit comments

Comments
 (0)