From e78d07514f0dfb6ad533117fe3ee23ab0e61fd64 Mon Sep 17 00:00:00 2001 From: nikita2206 Date: Mon, 18 Feb 2013 14:25:05 +0400 Subject: [PATCH 1/3] bug64070 fixed, xdebug needs fix too (and maybe opcode caches) --- Zend/tests/bug64070.phpt | 33 +++++++++++++++++++++++++++++++++ Zend/zend_compile.c | 6 ++++++ 2 files changed, 39 insertions(+) create mode 100644 Zend/tests/bug64070.phpt diff --git a/Zend/tests/bug64070.phpt b/Zend/tests/bug64070.phpt new file mode 100644 index 000000000000..e887a828c488 --- /dev/null +++ b/Zend/tests/bug64070.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #64070 (Inheritance with traits and aliased methods) +--FILE-- +bar(); +$n->foo(); + +?> +--EXPECT-- +bar +foo diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 1a8d10890060..7572ff304caf 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -3988,6 +3988,12 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args, && alias->trait_method->mname_len == fnname_len && (zend_binary_strcasecmp(alias->trait_method->method_name, alias->trait_method->mname_len, fn->common.function_name, fnname_len) == 0)) { fn_copy = *fn; + + /* Switch the name of the aliased function to the alias so that derived classes will get alias and not original name */ + int alias_len = strlen(alias->alias); + char *alias_func_name = malloc(alias_len); + memcpy(alias_func_name, alias->alias, alias_len); + fn_copy.common.function_name = alias_func_name; /* if it is 0, no modifieres has been changed */ if (alias->modifiers) { From 1de1742e3451f74225b864228bdc2cd0f9a64990 Mon Sep 17 00:00:00 2001 From: nikita2206 Date: Mon, 18 Feb 2013 16:16:27 +0400 Subject: [PATCH 2/3] but 64070 changed manual allocation/memcpy-ing of the string to estrdup --- Zend/zend_compile.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 7572ff304caf..30ae56dc6970 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -3990,10 +3990,7 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args, fn_copy = *fn; /* Switch the name of the aliased function to the alias so that derived classes will get alias and not original name */ - int alias_len = strlen(alias->alias); - char *alias_func_name = malloc(alias_len); - memcpy(alias_func_name, alias->alias, alias_len); - fn_copy.common.function_name = alias_func_name; + fn_copy.common.function_name = estrdup(alias->alias); /* if it is 0, no modifieres has been changed */ if (alias->modifiers) { From 691d31ca8c15e1d9940cf3c0773468f570e5b584 Mon Sep 17 00:00:00 2001 From: nikita2206 Date: Mon, 18 Feb 2013 16:33:53 +0400 Subject: [PATCH 3/3] bug 64070 changed estrdup to estrndup --- Zend/zend_compile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 30ae56dc6970..6adceb4f72be 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -3990,7 +3990,7 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args, fn_copy = *fn; /* Switch the name of the aliased function to the alias so that derived classes will get alias and not original name */ - fn_copy.common.function_name = estrdup(alias->alias); + fn_copy.common.function_name = estrndup(alias->alias, alias->alias_len); /* if it is 0, no modifieres has been changed */ if (alias->modifiers) {