From 72027cd0848f1a5c580c601573448cdea9b095ca Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Wed, 28 Aug 2013 20:33:42 -0700 Subject: [PATCH] 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. --- NEWS | 2 ++ Zend/tests/bug65579.phpt | 29 +++++++++++++++++++++++++++++ Zend/zend_API.c | 17 +++++++++-------- 3 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 Zend/tests/bug65579.phpt diff --git a/NEWS b/NEWS index 093fa20626c8b..b718a74e45120 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,8 @@ PHP NEWS ?? ??? 2013, PHP 5.4.20 - Core: + . Fixed bug #65579 (Using traits with get_class_methods causes segfault). + (Adam) . Fixed bug #65490 (Duplicate calls to get lineno & filename for DTRACE_FUNCTION_*). (Chris Jones) . Fixed bug #65483 (quoted-printable encode stream filter incorrectly encoding diff --git a/Zend/tests/bug65579.phpt b/Zend/tests/bug65579.phpt new file mode 100644 index 0000000000000..25d74ed4f5ee4 --- /dev/null +++ b/Zend/tests/bug65579.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #65579 (Using traits with get_class_methods causes segfault) +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + string(10) "testMethod" + [1]=> + string(25) "testmethodfromparenttrait" +} diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 90d27b79878b7..870a9b6480187 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -3917,15 +3917,16 @@ ZEND_API const char* zend_find_alias_name(zend_class_entry *ce, const char *name { zend_trait_alias *alias, **alias_ptr; - alias_ptr = ce->trait_aliases; - alias = *alias_ptr; - while (alias) { - if (alias->alias_len == len && - !strncasecmp(name, alias->alias, alias->alias_len)) { - return alias->alias; - } - alias_ptr++; + if (alias_ptr = ce->trait_aliases) { alias = *alias_ptr; + while (alias) { + if (alias->alias_len == len && + !strncasecmp(name, alias->alias, alias->alias_len)) { + return alias->alias; + } + alias_ptr++; + alias = *alias_ptr; + } } return name;