Skip to content

Commit 8a750bb

Browse files
committed
internal-default-verification
1 parent 927b9ee commit 8a750bb

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

Zend/zend_execute.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4888,6 +4888,44 @@ static void cleanup_unfinished_calls(zend_execute_data *execute_data, uint32_t o
48884888
}
48894889
/* }}} */
48904890

4891+
/* Replace optional parameters that weren't passed with their declared default values,
4892+
* which allows us to check that this does not change the behavior of the function. */
4893+
#define ZEND_VERIFY_INTERNAL_PARAM_DEFAULTS 1
4894+
#if ZEND_VERIFY_INTERNAL_PARAM_DEFAULTS
4895+
static void zend_verify_internal_param_defaults(zend_execute_data **call_ptr) {
4896+
zend_function *fbc = (*call_ptr)->func;
4897+
uint32_t num_passed_args = ZEND_CALL_NUM_ARGS(*call_ptr);
4898+
if (num_passed_args < fbc->common.required_num_args) {
4899+
/* This is an error anyway. */
4900+
return;
4901+
}
4902+
4903+
uint32_t num_declared_args = fbc->common.num_args;
4904+
while (num_passed_args < num_declared_args) {
4905+
zend_internal_arg_info *arg_info = (zend_internal_arg_info *)&fbc->internal_function.arg_info[num_passed_args];
4906+
zval default_value;
4907+
if (zend_get_default_from_internal_arg_info(&default_value, (zend_arg_info *)arg_info) == FAILURE) {
4908+
/* Default value not available, so we can't pass any further defaults either. */
4909+
return;
4910+
}
4911+
4912+
if (Z_TYPE(default_value) == IS_CONSTANT_AST) {
4913+
zval_update_constant_ex(&default_value, fbc->common.scope);
4914+
}
4915+
4916+
zend_vm_stack_extend_call_frame(call_ptr, num_passed_args, 1);
4917+
zval *arg = ZEND_CALL_VAR_NUM(*call_ptr, num_passed_args);
4918+
ZVAL_COPY_VALUE(arg, &default_value);
4919+
if (ARG_SHOULD_BE_SENT_BY_REF(fbc, num_passed_args + 1)) {
4920+
ZVAL_MAKE_REF(arg);
4921+
}
4922+
4923+
num_passed_args++;
4924+
ZEND_CALL_NUM_ARGS(*call_ptr)++;
4925+
}
4926+
}
4927+
#endif
4928+
48914929
static void cleanup_live_vars(zend_execute_data *execute_data, uint32_t op_num, uint32_t catch_op_num) /* {{{ */
48924930
{
48934931
int i;

Zend/zend_vm_def.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4108,6 +4108,9 @@ ZEND_VM_HOT_HANDLER(129, ZEND_DO_ICALL, ANY, ANY, SPEC(RETVAL,OBSERVER))
41084108
zval retval;
41094109

41104110
SAVE_OPLINE();
4111+
#if ZEND_VERIFY_INTERNAL_PARAM_DEFAULTS
4112+
zend_verify_internal_param_defaults(&call);
4113+
#endif
41114114
EX(call) = call->prev_execute_data;
41124115

41134116
call->prev_execute_data = execute_data;

Zend/zend_vm_execute.h

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)