From 57c1335fec064d8022d3d86b01ceb4eea0a027a7 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 28 Nov 2013 11:44:14 +0400 Subject: [PATCH] Don't check argument types for internal functions without type hinting --- Zend/zend_API.c | 13 +++++++++++++ Zend/zend_compile.h | 3 +++ Zend/zend_vm_def.h | 2 +- Zend/zend_vm_execute.h | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 56b1fda24b..23729ea185 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2138,6 +2138,19 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio str_efree(lowercase_name); break; } + + /* If types of arguments have to be checked */ + if (reg_function->common.arg_info && reg_function->common.num_args) { + int i; + for (i = 0; i < reg_function->common.num_args; i++) { + if (reg_function->common.arg_info[i].class_name || + reg_function->common.arg_info[i].type_hint) { + reg_function->common.fn_flags |= ZEND_ACC_HAS_TYPE_HINTS; + break; + } + } + } + if (scope) { /* Look for ctor, dtor, clone * If it's an old-style constructor, store it only if we don't have diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 23c5b22efd..5e284880e1 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -212,6 +212,9 @@ typedef struct _zend_try_catch_element { #define ZEND_ACC_RETURN_REFERENCE 0x4000000 #define ZEND_ACC_DONE_PASS_TWO 0x8000000 +/* function has arguments with type hinting */ +#define ZEND_ACC_HAS_TYPE_HINTS 0x10000000 + char *zend_visibility_string(zend_uint fn_flags); diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 45cfe909a3..6eca6d0119 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -1951,7 +1951,7 @@ ZEND_VM_HELPER(zend_do_fcall_common_helper, ANY, ANY) LOAD_OPLINE(); if (fbc->type == ZEND_INTERNAL_FUNCTION) { - if (fbc->common.arg_info) { + if (fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) { zend_uint i=0; zval **p = (zval**)EX(function_state).arguments; ulong arg_count = opline->extended_value; diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 107e460c88..dcb11836d6 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -530,7 +530,7 @@ static int ZEND_FASTCALL zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_AR LOAD_OPLINE(); if (fbc->type == ZEND_INTERNAL_FUNCTION) { - if (fbc->common.arg_info) { + if (fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) { zend_uint i=0; zval **p = (zval**)EX(function_state).arguments; ulong arg_count = opline->extended_value; -- 2.40.0