com php-src: Check num required args is correct in debug builds: Zend/zend_execute.c Zend/zend_vm_def.h Zend/zend _vm_execute.h

From: Date: Mon, 07 Oct 2019 14:34:05 +0000
Subject: com php-src: Check num required args is correct in debug builds: Zend/zend_execute.c Zend/zend_vm_def.h Zend/zend _vm_execute.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-108768@lists.php.net to get a copy of this message
Commit: 57670c6769039a2e7b6379a68f04ecc9cb127101 Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 7 Oct 2019 11:23:51 +0200 Parents: 5f80eb7842f377e5f3ad68c58039f3146a9174bd Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=57670c6769039a2e7b6379a68f04ecc9cb127101 Log: Check num required args is correct in debug builds Also replace the assertion failure with an E_CORE_ERROR that includes the function name, so these are easier to debug. Changed paths: M Zend/zend_execute.c M Zend/zend_vm_def.h M Zend/zend_vm_execute.h

diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index afa8804c9bd..5aaf415adfd 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1079,6 +1079,33 @@ static zend_never_inline ZEND_ATTRIBUTE_UNUSED int zend_verify_internal_arg_type return 1; } +#if ZEND_DEBUG +/* Determine whether an internal call should throw, because the passed arguments violate + * an arginfo constraint. This is only checked in debug builds. In release builds, we + * trust that arginfo matches what is enforced by zend_parse_parameters. */ +static zend_always_inline zend_bool zend_internal_call_should_throw(zend_function *fbc, zend_execute_data *call) +{ + if (fbc->common.required_num_args > ZEND_CALL_NUM_ARGS(call)) { + return 1; + } + + if ((fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && + !zend_verify_internal_arg_types(fbc, call)) { + return 1; + } + + return 0; +} + +static ZEND_COLD void zend_internal_call_arginfo_violation(zend_function *fbc) +{ + zend_error(E_CORE_ERROR, "Arginfo / zpp mismatch during call of %s%s%s()", + fbc->common.scope ? ZSTR_VAL(fbc->common.scope->name) : "", + fbc->common.scope ? "::" : "", + ZSTR_VAL(fbc->common.function_name)); +} +#endif + ZEND_API ZEND_COLD void ZEND_FASTCALL zend_missing_arg_error(zend_execute_data *execute_data) { zend_execute_data *ptr = EX(prev_execute_data); diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 6fa82545e70..4d60feabd11 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -3949,12 +3949,7 @@ ZEND_VM_HOT_HANDLER(129, ZEND_DO_ICALL, ANY, ANY, SPEC(RETVAL)) EG(current_execute_data) = call; #if ZEND_DEBUG - /* Type checks for internal functions are usually only performed by zpp. - * In debug mode we additionally run arginfo checks to detect cases where - * arginfo and zpp went out of sync. */ - zend_bool wrong_arg_types = - (fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && - !zend_verify_internal_arg_types(fbc, call); + zend_bool should_throw = zend_internal_call_should_throw(fbc, call); #endif ret = RETURN_VALUE_USED(opline) ? EX_VAR(opline->result.var) : &retval; @@ -3964,7 +3959,9 @@ ZEND_VM_HOT_HANDLER(129, ZEND_DO_ICALL, ANY, ANY, SPEC(RETVAL)) #if ZEND_DEBUG if (!EG(exception) && call->func) { - ZEND_ASSERT(!wrong_arg_types && "Arginfo / zpp type mismatch?"); + if (should_throw) { + zend_internal_call_arginfo_violation(call->func); + } ZEND_ASSERT(!(call->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || zend_verify_internal_return_type(call->func, ret)); ZEND_ASSERT((call->func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) @@ -4054,12 +4051,7 @@ ZEND_VM_HOT_HANDLER(131, ZEND_DO_FCALL_BY_NAME, ANY, ANY, SPEC(RETVAL)) EG(current_execute_data) = call; #if ZEND_DEBUG - /* Type checks for internal functions are usually only performed by zpp. - * In debug mode we additionally run arginfo checks to detect cases where - * arginfo and zpp went out of sync. */ - zend_bool wrong_arg_types = - (fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && - !zend_verify_internal_arg_types(fbc, call); + zend_bool should_throw = zend_internal_call_should_throw(fbc, call); #endif ret = RETURN_VALUE_USED(opline) ? EX_VAR(opline->result.var) : &retval; @@ -4069,7 +4061,9 @@ ZEND_VM_HOT_HANDLER(131, ZEND_DO_FCALL_BY_NAME, ANY, ANY, SPEC(RETVAL)) #if ZEND_DEBUG if (!EG(exception) && call->func) { - ZEND_ASSERT(!wrong_arg_types && "Arginfo / zpp type mismatch?"); + if (should_throw) { + zend_internal_call_arginfo_violation(call->func); + } ZEND_ASSERT(!(call->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || zend_verify_internal_return_type(call->func, ret)); ZEND_ASSERT((call->func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) @@ -4146,12 +4140,7 @@ ZEND_VM_HOT_HANDLER(60, ZEND_DO_FCALL, ANY, ANY, SPEC(RETVAL)) EG(current_execute_data) = call; #if ZEND_DEBUG - /* Type checks for internal functions are usually only performed by zpp. - * In debug mode we additionally run arginfo checks to detect cases where - * arginfo and zpp went out of sync. */ - zend_bool wrong_arg_types = - (fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && - !zend_verify_internal_arg_types(fbc, call); + zend_bool should_throw = zend_internal_call_should_throw(fbc, call); #endif ret = RETURN_VALUE_USED(opline) ? EX_VAR(opline->result.var) : &retval; @@ -4166,7 +4155,9 @@ ZEND_VM_HOT_HANDLER(60, ZEND_DO_FCALL, ANY, ANY, SPEC(RETVAL)) #if ZEND_DEBUG if (!EG(exception) && call->func) { - ZEND_ASSERT(!wrong_arg_types && "Arginfo / zpp type mismatch?"); + if (should_throw) { + zend_internal_call_arginfo_violation(call->func); + } ZEND_ASSERT(!(call->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || zend_verify_internal_return_type(call->func, ret)); ZEND_ASSERT((call->func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) @@ -8212,12 +8203,7 @@ ZEND_VM_HANDLER(158, ZEND_CALL_TRAMPOLINE, ANY, ANY) EG(current_execute_data) = call; #if ZEND_DEBUG - /* Type checks for internal functions are usually only performed by zpp. - * In debug mode we additionally run arginfo checks to detect cases where - * arginfo and zpp went out of sync. */ - zend_bool wrong_arg_types = - (fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && - !zend_verify_internal_arg_types(fbc, call); + zend_bool should_throw = zend_internal_call_should_throw(fbc, call); #endif if (ret == NULL) { @@ -8234,7 +8220,9 @@ ZEND_VM_HANDLER(158, ZEND_CALL_TRAMPOLINE, ANY, ANY) #if ZEND_DEBUG if (!EG(exception) && call->func) { - ZEND_ASSERT(!wrong_arg_types && "Arginfo / zpp type mismatch?"); + if (should_throw) { + zend_internal_call_arginfo_violation(call->func); + } ZEND_ASSERT(!(call->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || zend_verify_internal_return_type(call->func, ret)); ZEND_ASSERT((call->func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 6bd3add11c2..2b29fb63bb4 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -1257,12 +1257,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_ICALL_SPEC_RETV EG(current_execute_data) = call; #if ZEND_DEBUG - /* Type checks for internal functions are usually only performed by zpp. - * In debug mode we additionally run arginfo checks to detect cases where - * arginfo and zpp went out of sync. */ - zend_bool wrong_arg_types = - (fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && - !zend_verify_internal_arg_types(fbc, call); + zend_bool should_throw = zend_internal_call_should_throw(fbc, call); #endif ret = 0 ? EX_VAR(opline->result.var) : &retval; @@ -1272,7 +1267,9 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_ICALL_SPEC_RETV #if ZEND_DEBUG if (!EG(exception) && call->func) { - ZEND_ASSERT(!wrong_arg_types && "Arginfo / zpp type mismatch?"); + if (should_throw) { + zend_internal_call_arginfo_violation(call->func); + } ZEND_ASSERT(!(call->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || zend_verify_internal_return_type(call->func, ret)); ZEND_ASSERT((call->func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) @@ -1312,12 +1309,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_ICALL_SPEC_RETV EG(current_execute_data) = call; #if ZEND_DEBUG - /* Type checks for internal functions are usually only performed by zpp. - * In debug mode we additionally run arginfo checks to detect cases where - * arginfo and zpp went out of sync. */ - zend_bool wrong_arg_types = - (fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && - !zend_verify_internal_arg_types(fbc, call); + zend_bool should_throw = zend_internal_call_should_throw(fbc, call); #endif ret = 1 ? EX_VAR(opline->result.var) : &retval; @@ -1327,7 +1319,9 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_ICALL_SPEC_RETV #if ZEND_DEBUG if (!EG(exception) && call->func) { - ZEND_ASSERT(!wrong_arg_types && "Arginfo / zpp type mismatch?"); + if (should_throw) { + zend_internal_call_arginfo_violation(call->func); + } ZEND_ASSERT(!(call->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || zend_verify_internal_return_type(call->func, ret)); ZEND_ASSERT((call->func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) @@ -1440,12 +1434,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_S EG(current_execute_data) = call; #if ZEND_DEBUG - /* Type checks for internal functions are usually only performed by zpp. - * In debug mode we additionally run arginfo checks to detect cases where - * arginfo and zpp went out of sync. */ - zend_bool wrong_arg_types = - (fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && - !zend_verify_internal_arg_types(fbc, call); + zend_bool should_throw = zend_internal_call_should_throw(fbc, call); #endif ret = 0 ? EX_VAR(opline->result.var) : &retval; @@ -1455,7 +1444,9 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_S #if ZEND_DEBUG if (!EG(exception) && call->func) { - ZEND_ASSERT(!wrong_arg_types && "Arginfo / zpp type mismatch?"); + if (should_throw) { + zend_internal_call_arginfo_violation(call->func); + } ZEND_ASSERT(!(call->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || zend_verify_internal_return_type(call->func, ret)); ZEND_ASSERT((call->func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) @@ -1524,12 +1515,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_S EG(current_execute_data) = call; #if ZEND_DEBUG - /* Type checks for internal functions are usually only performed by zpp. - * In debug mode we additionally run arginfo checks to detect cases where - * arginfo and zpp went out of sync. */ - zend_bool wrong_arg_types = - (fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && - !zend_verify_internal_arg_types(fbc, call); + zend_bool should_throw = zend_internal_call_should_throw(fbc, call); #endif ret = 1 ? EX_VAR(opline->result.var) : &retval; @@ -1539,7 +1525,9 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_S #if ZEND_DEBUG if (!EG(exception) && call->func) { - ZEND_ASSERT(!wrong_arg_types && "Arginfo / zpp type mismatch?"); + if (should_throw) { + zend_internal_call_arginfo_violation(call->func); + } ZEND_ASSERT(!(call->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || zend_verify_internal_return_type(call->func, ret)); ZEND_ASSERT((call->func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) @@ -1616,12 +1604,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_RETV EG(current_execute_data) = call; #if ZEND_DEBUG - /* Type checks for internal functions are usually only performed by zpp. - * In debug mode we additionally run arginfo checks to detect cases where - * arginfo and zpp went out of sync. */ - zend_bool wrong_arg_types = - (fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && - !zend_verify_internal_arg_types(fbc, call); + zend_bool should_throw = zend_internal_call_should_throw(fbc, call); #endif ret = 0 ? EX_VAR(opline->result.var) : &retval; @@ -1636,7 +1619,9 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_RETV #if ZEND_DEBUG if (!EG(exception) && call->func) { - ZEND_ASSERT(!wrong_arg_types && "Arginfo / zpp type mismatch?"); + if (should_throw) { + zend_internal_call_arginfo_violation(call->func); + } ZEND_ASSERT(!(call->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || zend_verify_internal_return_type(call->func, ret)); ZEND_ASSERT((call->func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) @@ -1717,12 +1702,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_RETV EG(current_execute_data) = call; #if ZEND_DEBUG - /* Type checks for internal functions are usually only performed by zpp. - * In debug mode we additionally run arginfo checks to detect cases where - * arginfo and zpp went out of sync. */ - zend_bool wrong_arg_types = - (fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && - !zend_verify_internal_arg_types(fbc, call); + zend_bool should_throw = zend_internal_call_should_throw(fbc, call); #endif ret = 1 ? EX_VAR(opline->result.var) : &retval; @@ -1737,7 +1717,9 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_RETV #if ZEND_DEBUG if (!EG(exception) && call->func) { - ZEND_ASSERT(!wrong_arg_types && "Arginfo / zpp type mismatch?"); + if (should_throw) { + zend_internal_call_arginfo_violation(call->func); + } ZEND_ASSERT(!(call->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || zend_verify_internal_return_type(call->func, ret)); ZEND_ASSERT((call->func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) @@ -2782,12 +2764,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CALL_TRAMPOLINE_SPEC_HANDLER(Z EG(current_execute_data) = call; #if ZEND_DEBUG - /* Type checks for internal functions are usually only performed by zpp. - * In debug mode we additionally run arginfo checks to detect cases where - * arginfo and zpp went out of sync. */ - zend_bool wrong_arg_types = - (fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && - !zend_verify_internal_arg_types(fbc, call); + zend_bool should_throw = zend_internal_call_should_throw(fbc, call); #endif if (ret == NULL) { @@ -2804,7 +2781,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CALL_TRAMPOLINE_SPEC_HANDLER(Z #if ZEND_DEBUG if (!EG(exception) && call->func) { - ZEND_ASSERT(!wrong_arg_types && "Arginfo / zpp type mismatch?"); + if (should_throw) { + zend_internal_call_arginfo_violation(call->func); + } ZEND_ASSERT(!(call->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || zend_verify_internal_return_type(call->func, ret)); ZEND_ASSERT((call->func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE)
« previous php.cvs (#108768) next »