Skip to content

Commit 72027cd

Browse files
committed
Fix bug #65579 (Using traits with get_class_methods causes segfault).
Specifically, this checks if there are trait aliases defined in the class scope before attempting to dereference the first trait alias. This handles the case where a trait alias was used in a child trait but no aliases exist in the concrete class.
1 parent 3745bda commit 72027cd

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ PHP NEWS
33
?? ??? 2013, PHP 5.4.20
44

55
- Core:
6+
. Fixed bug #65579 (Using traits with get_class_methods causes segfault).
7+
(Adam)
68
. Fixed bug #65490 (Duplicate calls to get lineno & filename for
79
DTRACE_FUNCTION_*). (Chris Jones)
810
. Fixed bug #65483 (quoted-printable encode stream filter incorrectly encoding

Zend/tests/bug65579.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Bug #65579 (Using traits with get_class_methods causes segfault)
3+
--FILE--
4+
<?php
5+
trait ParentTrait {
6+
public function testMethod() { }
7+
}
8+
9+
trait ChildTrait {
10+
use ParentTrait {
11+
testMethod as testMethodFromParentTrait;
12+
}
13+
public function testMethod() { }
14+
}
15+
16+
class TestClass {
17+
use ChildTrait;
18+
}
19+
20+
$obj = new TestClass();
21+
var_dump(get_class_methods($obj));
22+
?>
23+
--EXPECT--
24+
array(2) {
25+
[0]=>
26+
string(10) "testMethod"
27+
[1]=>
28+
string(25) "testmethodfromparenttrait"
29+
}

Zend/zend_API.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3917,15 +3917,16 @@ ZEND_API const char* zend_find_alias_name(zend_class_entry *ce, const char *name
39173917
{
39183918
zend_trait_alias *alias, **alias_ptr;
39193919

3920-
alias_ptr = ce->trait_aliases;
3921-
alias = *alias_ptr;
3922-
while (alias) {
3923-
if (alias->alias_len == len &&
3924-
!strncasecmp(name, alias->alias, alias->alias_len)) {
3925-
return alias->alias;
3926-
}
3927-
alias_ptr++;
3920+
if (alias_ptr = ce->trait_aliases) {
39283921
alias = *alias_ptr;
3922+
while (alias) {
3923+
if (alias->alias_len == len &&
3924+
!strncasecmp(name, alias->alias, alias->alias_len)) {
3925+
return alias->alias;
3926+
}
3927+
alias_ptr++;
3928+
alias = *alias_ptr;
3929+
}
39293930
}
39303931

39313932
return name;

0 commit comments

Comments
 (0)