From 38f9c8d93da66e191116dd23b6ea7ede494c71f2 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 18 Apr 2019 02:31:12 +0300 Subject: [PATCH] Don't initialize return value before calling user functions --- Zend/zend_vm_def.h | 8 ++++---- Zend/zend_vm_execute.h | 13 ++++--------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index a853b86653..9f2fba4fbf 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -3878,7 +3878,6 @@ ZEND_VM_HOT_HANDLER(130, ZEND_DO_UCALL, ANY, ANY, SPEC(RETVAL)) ret = NULL; if (RETURN_VALUE_USED(opline)) { ret = EX_VAR(opline->result.var); - ZVAL_NULL(ret); } call->prev_execute_data = execute_data; @@ -3903,7 +3902,6 @@ ZEND_VM_HOT_HANDLER(131, ZEND_DO_FCALL_BY_NAME, ANY, ANY, SPEC(RETVAL)) ret = NULL; if (RETURN_VALUE_USED(opline)) { ret = EX_VAR(opline->result.var); - ZVAL_NULL(ret); } call->prev_execute_data = execute_data; @@ -3991,7 +3989,6 @@ ZEND_VM_HOT_HANDLER(60, ZEND_DO_FCALL, ANY, ANY, SPEC(RETVAL)) ret = NULL; if (RETURN_VALUE_USED(opline)) { ret = EX_VAR(opline->result.var); - ZVAL_NULL(ret); } call->prev_execute_data = execute_data; @@ -5701,7 +5698,6 @@ ZEND_VM_HANDLER(73, ZEND_INCLUDE_OR_EVAL, CONST|TMPVAR|CV, ANY, EVAL) if (RETURN_VALUE_USED(opline)) { return_value = EX_VAR(opline->result.var); - ZVAL_NULL(return_value); } new_op_array->scope = EX(func)->op_array.scope; @@ -7196,6 +7192,10 @@ ZEND_VM_HELPER(zend_dispatch_try_catch_finally_helper, ANY, ANY, uint32_t try_ca zend_generator_close(generator, 1); ZEND_VM_RETURN(); } else { + /* We didn't execute RETURN, and have to initialize return_value */ + if (EX(return_value)) { + ZVAL_UNDEF(EX(return_value)); + } ZEND_VM_DISPATCH_TO_HELPER(zend_leave_helper); } } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index d14af785b9..d4aac71756 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -995,7 +995,6 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_UCALL_SPEC_RETV ret = NULL; if (0) { ret = EX_VAR(opline->result.var); - ZVAL_NULL(ret); } call->prev_execute_data = execute_data; @@ -1019,7 +1018,6 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_UCALL_SPEC_RETV ret = NULL; if (1) { ret = EX_VAR(opline->result.var); - ZVAL_NULL(ret); } call->prev_execute_data = execute_data; @@ -1044,7 +1042,6 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_S ret = NULL; if (0) { ret = EX_VAR(opline->result.var); - ZVAL_NULL(ret); } call->prev_execute_data = execute_data; @@ -1121,7 +1118,6 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_S ret = NULL; if (1) { ret = EX_VAR(opline->result.var); - ZVAL_NULL(ret); } call->prev_execute_data = execute_data; @@ -1209,7 +1205,6 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_RETV ret = NULL; if (0) { ret = EX_VAR(opline->result.var); - ZVAL_NULL(ret); } call->prev_execute_data = execute_data; @@ -1320,7 +1315,6 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_RETV ret = NULL; if (1) { ret = EX_VAR(opline->result.var); - ZVAL_NULL(ret); } call->prev_execute_data = execute_data; @@ -1964,6 +1958,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_dispatch_try_catch_finally_hel zend_generator_close(generator, 1); ZEND_VM_RETURN(); } else { + /* We didn't execute RETURN, and have to initialize return_value */ + if (EX(return_value)) { + ZVAL_UNDEF(EX(return_value)); + } ZEND_VM_TAIL_CALL(zend_leave_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)); } } @@ -3454,7 +3452,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INCLUDE_OR_EVAL_SPEC_CONST_HAN if (RETURN_VALUE_USED(opline)) { return_value = EX_VAR(opline->result.var); - ZVAL_NULL(return_value); } new_op_array->scope = EX(func)->op_array.scope; @@ -12925,7 +12922,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INCLUDE_OR_EVAL_SPEC_TMPVAR_HA if (RETURN_VALUE_USED(opline)) { return_value = EX_VAR(opline->result.var); - ZVAL_NULL(return_value); } new_op_array->scope = EX(func)->op_array.scope; @@ -39960,7 +39956,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INCLUDE_OR_EVAL_SPEC_CV_HANDLE if (RETURN_VALUE_USED(opline)) { return_value = EX_VAR(opline->result.var); - ZVAL_NULL(return_value); } new_op_array->scope = EX(func)->op_array.scope; -- 2.40.0