From cc23d3bade433999c6adb007d9d779ed6ddb7f98 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Tue, 3 Jun 2008 18:11:12 +0000 Subject: [PATCH] - Fixed bug #45089 (__callStatic $name case sensitivity) --- Zend/tests/call_static.phpt | 6 +- Zend/zend_compile.c | 5 +- Zend/zend_execute_API.c | 7 +- Zend/zend_object_handlers.c | 9 +- Zend/zend_vm_def.h | 20 ++-- Zend/zend_vm_execute.h | 200 ++++++++++++++++++++---------------- 6 files changed, 134 insertions(+), 113 deletions(-) diff --git a/Zend/tests/call_static.phpt b/Zend/tests/call_static.phpt index e77a158914..c37bc72230 100755 --- a/Zend/tests/call_static.phpt +++ b/Zend/tests/call_static.phpt @@ -15,6 +15,6 @@ call_user_func(array("Test", "Three"), NULL, 0, false); Test::Four(5, 6, 7, 8); --EXPECT-- -two() called with 2 arguments -three() called with 3 arguments -four() called with 4 arguments +Two() called with 2 arguments +Three() called with 3 arguments +Four() called with 4 arguments diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 476e2d04e7..aaeb6500d9 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1919,11 +1919,8 @@ int zend_do_begin_class_member_function_call(znode *class_name, znode *method_na memcmp(lcname, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1) == 0) { zval_dtor(&method_name->u.constant); SET_UNUSED(*method_name); - efree(lcname); - } else { - efree(Z_STRVAL(method_name->u.constant)); - Z_STRVAL(method_name->u.constant) = lcname; } + efree(lcname); } if (class_name->op_type == IS_CONST && diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index 929828654b..6e351000e2 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -901,14 +901,11 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS efree(function_name_lc); } } else if (calling_scope) { - char *function_name_lc = zend_str_tolower_dup(fname, fname_len); - if (calling_scope->get_static_method) { - EX(function_state).function = calling_scope->get_static_method(calling_scope, function_name_lc, fname_len TSRMLS_CC); + EX(function_state).function = calling_scope->get_static_method(calling_scope, fname, fname_len TSRMLS_CC); } else { - EX(function_state).function = zend_std_get_static_method(calling_scope, function_name_lc, fname_len TSRMLS_CC); + EX(function_state).function = zend_std_get_static_method(calling_scope, fname, fname_len TSRMLS_CC); } - efree(function_name_lc); if (check_scope_or_static && EX(function_state).function && !(EX(function_state).function->common.fn_flags & ZEND_ACC_STATIC) diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 71f843b339..cf5ebd4807 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -893,7 +893,9 @@ ZEND_API void zend_std_callstatic_user_call(INTERNAL_FUNCTION_PARAMETERS) /* {{{ ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, char *function_name_strval, int function_name_strlen TSRMLS_DC) /* {{{ */ { zend_function *fbc = NULL; - char *lc_class_name; + char *lc_class_name, *lc_function_name = NULL; + + lc_function_name = zend_str_tolower_dup(function_name_strval, function_name_strlen); if (function_name_strlen == ce->name_length && ce->constructor) { lc_class_name = zend_str_tolower_dup(ce->name, ce->name_length); @@ -902,7 +904,9 @@ ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, char *f } efree(lc_class_name); } - if (!fbc && zend_hash_find(&ce->function_table, function_name_strval, function_name_strlen+1, (void **) &fbc)==FAILURE) { + if (!fbc && zend_hash_find(&ce->function_table, lc_function_name, function_name_strlen+1, (void **) &fbc)==FAILURE) { + efree(lc_function_name); + if (ce->__call && EG(This) && Z_OBJ_HT_P(EG(This))->get_class_entry && @@ -940,6 +944,7 @@ ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, char *f zend_error(E_ERROR, "Call to undefined method %s::%s()", ce->name ? ce->name : "", function_name_strval); } } + efree(lc_function_name); #if MBO_0 /* right now this function is used for non static method lookup too */ diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index d21c96592c..885629b82b 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -1942,7 +1942,7 @@ ZEND_VM_HANDLER(113, ZEND_INIT_STATIC_METHOD_CALL, CONST|VAR, CONST|TMP|VAR|UNUS } if(OP2_TYPE != IS_UNUSED) { char *function_name_strval; - int function_name_strlen; + int function_name_strlen = 0; zend_free_op free_op2; if (OP2_TYPE == IS_CONST) { @@ -1953,19 +1953,21 @@ ZEND_VM_HANDLER(113, ZEND_INIT_STATIC_METHOD_CALL, CONST|VAR, CONST|TMP|VAR|UNUS if (Z_TYPE_P(function_name) != IS_STRING) { zend_error_noreturn(E_ERROR, "Function name must be a string"); - } - function_name_strval = zend_str_tolower_dup(function_name->value.str.val, function_name->value.str.len); - function_name_strlen = function_name->value.str.len; + } else { + function_name_strval = Z_STRVAL_P(function_name); + function_name_strlen = Z_STRLEN_P(function_name); + } } - if (ce->get_static_method) { - EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); - } else { - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (function_name_strlen) { + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } } if (OP2_TYPE != IS_CONST) { - efree(function_name_strval); FREE_OP2(); } } else { diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 749d6e0b0a..cd7eba7a9c 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -2449,7 +2449,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_CONST_HANDLER(ZEND_OPCODE_HAN } if(IS_CONST != IS_UNUSED) { char *function_name_strval; - int function_name_strlen; + int function_name_strlen = 0; if (IS_CONST == IS_CONST) { @@ -2460,19 +2460,21 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_CONST_HANDLER(ZEND_OPCODE_HAN if (Z_TYPE_P(function_name) != IS_STRING) { zend_error_noreturn(E_ERROR, "Function name must be a string"); - } - function_name_strval = zend_str_tolower_dup(function_name->value.str.val, function_name->value.str.len); - function_name_strlen = function_name->value.str.len; + } else { + function_name_strval = Z_STRVAL_P(function_name); + function_name_strlen = Z_STRLEN_P(function_name); + } } - if (ce->get_static_method) { - EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); - } else { - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (function_name_strlen) { + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } } if (IS_CONST != IS_CONST) { - efree(function_name_strval); } } else { @@ -3020,7 +3022,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_TMP_HANDLER(ZEND_OPCODE_HANDL } if(IS_TMP_VAR != IS_UNUSED) { char *function_name_strval; - int function_name_strlen; + int function_name_strlen = 0; zend_free_op free_op2; if (IS_TMP_VAR == IS_CONST) { @@ -3031,19 +3033,21 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_TMP_HANDLER(ZEND_OPCODE_HANDL if (Z_TYPE_P(function_name) != IS_STRING) { zend_error_noreturn(E_ERROR, "Function name must be a string"); - } - function_name_strval = zend_str_tolower_dup(function_name->value.str.val, function_name->value.str.len); - function_name_strlen = function_name->value.str.len; + } else { + function_name_strval = Z_STRVAL_P(function_name); + function_name_strlen = Z_STRLEN_P(function_name); + } } - if (ce->get_static_method) { - EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); - } else { - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (function_name_strlen) { + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } } if (IS_TMP_VAR != IS_CONST) { - efree(function_name_strval); zval_dtor(free_op2.var); } } else { @@ -3486,7 +3490,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_VAR_HANDLER(ZEND_OPCODE_HANDL } if(IS_VAR != IS_UNUSED) { char *function_name_strval; - int function_name_strlen; + int function_name_strlen = 0; zend_free_op free_op2; if (IS_VAR == IS_CONST) { @@ -3497,19 +3501,21 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_VAR_HANDLER(ZEND_OPCODE_HANDL if (Z_TYPE_P(function_name) != IS_STRING) { zend_error_noreturn(E_ERROR, "Function name must be a string"); - } - function_name_strval = zend_str_tolower_dup(function_name->value.str.val, function_name->value.str.len); - function_name_strlen = function_name->value.str.len; + } else { + function_name_strval = Z_STRVAL_P(function_name); + function_name_strlen = Z_STRLEN_P(function_name); + } } - if (ce->get_static_method) { - EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); - } else { - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (function_name_strlen) { + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } } if (IS_VAR != IS_CONST) { - efree(function_name_strval); if (free_op2.var) {zval_ptr_dtor(&free_op2.var);}; } } else { @@ -3708,7 +3714,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_UNUSED_HANDLER(ZEND_OPCODE_HA } if(IS_UNUSED != IS_UNUSED) { char *function_name_strval; - int function_name_strlen; + int function_name_strlen = 0; if (IS_UNUSED == IS_CONST) { @@ -3719,19 +3725,21 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_UNUSED_HANDLER(ZEND_OPCODE_HA if (Z_TYPE_P(function_name) != IS_STRING) { zend_error_noreturn(E_ERROR, "Function name must be a string"); - } - function_name_strval = zend_str_tolower_dup(function_name->value.str.val, function_name->value.str.len); - function_name_strlen = function_name->value.str.len; + } else { + function_name_strval = Z_STRVAL_P(function_name); + function_name_strlen = Z_STRLEN_P(function_name); + } } - if (ce->get_static_method) { - EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); - } else { - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (function_name_strlen) { + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } } if (IS_UNUSED != IS_CONST) { - efree(function_name_strval); } } else { @@ -4142,7 +4150,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_CV_HANDLER(ZEND_OPCODE_HANDLE } if(IS_CV != IS_UNUSED) { char *function_name_strval; - int function_name_strlen; + int function_name_strlen = 0; if (IS_CV == IS_CONST) { @@ -4153,19 +4161,21 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_CV_HANDLER(ZEND_OPCODE_HANDLE if (Z_TYPE_P(function_name) != IS_STRING) { zend_error_noreturn(E_ERROR, "Function name must be a string"); - } - function_name_strval = zend_str_tolower_dup(function_name->value.str.val, function_name->value.str.len); - function_name_strlen = function_name->value.str.len; + } else { + function_name_strval = Z_STRVAL_P(function_name); + function_name_strlen = Z_STRLEN_P(function_name); + } } - if (ce->get_static_method) { - EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); - } else { - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (function_name_strlen) { + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } } if (IS_CV != IS_CONST) { - efree(function_name_strval); } } else { @@ -10078,7 +10088,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_CONST_HANDLER(ZEND_OPCODE_HANDL } if(IS_CONST != IS_UNUSED) { char *function_name_strval; - int function_name_strlen; + int function_name_strlen = 0; if (IS_CONST == IS_CONST) { @@ -10089,19 +10099,21 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_CONST_HANDLER(ZEND_OPCODE_HANDL if (Z_TYPE_P(function_name) != IS_STRING) { zend_error_noreturn(E_ERROR, "Function name must be a string"); - } - function_name_strval = zend_str_tolower_dup(function_name->value.str.val, function_name->value.str.len); - function_name_strlen = function_name->value.str.len; + } else { + function_name_strval = Z_STRVAL_P(function_name); + function_name_strlen = Z_STRLEN_P(function_name); + } } - if (ce->get_static_method) { - EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); - } else { - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (function_name_strlen) { + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } } if (IS_CONST != IS_CONST) { - efree(function_name_strval); } } else { @@ -11908,7 +11920,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_TMP_HANDLER(ZEND_OPCODE_HANDLER } if(IS_TMP_VAR != IS_UNUSED) { char *function_name_strval; - int function_name_strlen; + int function_name_strlen = 0; zend_free_op free_op2; if (IS_TMP_VAR == IS_CONST) { @@ -11919,19 +11931,21 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_TMP_HANDLER(ZEND_OPCODE_HANDLER if (Z_TYPE_P(function_name) != IS_STRING) { zend_error_noreturn(E_ERROR, "Function name must be a string"); - } - function_name_strval = zend_str_tolower_dup(function_name->value.str.val, function_name->value.str.len); - function_name_strlen = function_name->value.str.len; + } else { + function_name_strval = Z_STRVAL_P(function_name); + function_name_strlen = Z_STRLEN_P(function_name); + } } - if (ce->get_static_method) { - EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); - } else { - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (function_name_strlen) { + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } } if (IS_TMP_VAR != IS_CONST) { - efree(function_name_strval); zval_dtor(free_op2.var); } } else { @@ -13708,7 +13722,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_VAR_HANDLER(ZEND_OPCODE_HANDLER } if(IS_VAR != IS_UNUSED) { char *function_name_strval; - int function_name_strlen; + int function_name_strlen = 0; zend_free_op free_op2; if (IS_VAR == IS_CONST) { @@ -13719,19 +13733,21 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_VAR_HANDLER(ZEND_OPCODE_HANDLER if (Z_TYPE_P(function_name) != IS_STRING) { zend_error_noreturn(E_ERROR, "Function name must be a string"); - } - function_name_strval = zend_str_tolower_dup(function_name->value.str.val, function_name->value.str.len); - function_name_strlen = function_name->value.str.len; + } else { + function_name_strval = Z_STRVAL_P(function_name); + function_name_strlen = Z_STRLEN_P(function_name); + } } - if (ce->get_static_method) { - EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); - } else { - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (function_name_strlen) { + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } } if (IS_VAR != IS_CONST) { - efree(function_name_strval); if (free_op2.var) {zval_ptr_dtor(&free_op2.var);}; } } else { @@ -14611,7 +14627,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_UNUSED_HANDLER(ZEND_OPCODE_HAND } if(IS_UNUSED != IS_UNUSED) { char *function_name_strval; - int function_name_strlen; + int function_name_strlen = 0; if (IS_UNUSED == IS_CONST) { @@ -14622,19 +14638,21 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_UNUSED_HANDLER(ZEND_OPCODE_HAND if (Z_TYPE_P(function_name) != IS_STRING) { zend_error_noreturn(E_ERROR, "Function name must be a string"); - } - function_name_strval = zend_str_tolower_dup(function_name->value.str.val, function_name->value.str.len); - function_name_strlen = function_name->value.str.len; + } else { + function_name_strval = Z_STRVAL_P(function_name); + function_name_strlen = Z_STRLEN_P(function_name); + } } - if (ce->get_static_method) { - EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); - } else { - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (function_name_strlen) { + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } } if (IS_UNUSED != IS_CONST) { - efree(function_name_strval); } } else { @@ -16112,7 +16130,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_CV_HANDLER(ZEND_OPCODE_HANDLER_ } if(IS_CV != IS_UNUSED) { char *function_name_strval; - int function_name_strlen; + int function_name_strlen = 0; if (IS_CV == IS_CONST) { @@ -16123,19 +16141,21 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_CV_HANDLER(ZEND_OPCODE_HANDLER_ if (Z_TYPE_P(function_name) != IS_STRING) { zend_error_noreturn(E_ERROR, "Function name must be a string"); - } - function_name_strval = zend_str_tolower_dup(function_name->value.str.val, function_name->value.str.len); - function_name_strlen = function_name->value.str.len; + } else { + function_name_strval = Z_STRVAL_P(function_name); + function_name_strlen = Z_STRLEN_P(function_name); + } } - if (ce->get_static_method) { - EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); - } else { - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (function_name_strlen) { + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } } if (IS_CV != IS_CONST) { - efree(function_name_strval); } } else { -- 2.40.0