1
0
mirror of https://github.com/php/php-src.git synced 2026-04-16 04:21:18 +02:00

Fixed ability to call plain functions through zend_call_method()

This commit is contained in:
Dmitry Stogov
2018-06-25 23:01:21 +03:00
parent b89ce98129
commit 49a4e69584
3 changed files with 29 additions and 6 deletions

View File

@@ -2572,6 +2572,21 @@ ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function(zend_string *name) /*
return NULL;
} /* }}} */
ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function_str(const char *name, size_t len) /* {{{ */
{
zval *zv = zend_hash_str_find(EG(function_table), name, len);
if (EXPECTED(zv != NULL)) {
zend_function *fbc = Z_FUNC_P(zv);
if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!fbc->op_array.run_time_cache)) {
fbc = (zend_function*)init_func_run_time_cache_i(&fbc->op_array, zv);
}
return fbc;
}
return NULL;
} /* }}} */
static zend_always_inline void i_init_code_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value) /* {{{ */
{
ZEND_ASSERT(EX(func) == (zend_function*)op_array);

View File

@@ -309,6 +309,7 @@ ZEND_API zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, con
void zend_verify_abstract_class(zend_class_entry *ce);
ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function(zend_string *name);
ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function_str(const char *name, size_t len);
ZEND_API void zend_fetch_dimension_const(zval *result, zval *container, zval *dim, int type);

View File

@@ -67,12 +67,19 @@ ZEND_API zval* zend_call_method(zval *object, zend_class_entry *obj_ce, zend_fun
obj_ce = object ? Z_OBJCE_P(object) : NULL;
}
if (!fn_proxy || !*fn_proxy) {
HashTable *function_table = obj_ce ? &obj_ce->function_table : EG(function_table);
fcic.function_handler = zend_hash_str_find_ptr(
function_table, function_name, function_name_len);
if (fcic.function_handler == NULL) {
/* error at c-level */
zend_error_noreturn(E_CORE_ERROR, "Couldn't find implementation for method %s%s%s", obj_ce ? ZSTR_VAL(obj_ce->name) : "", obj_ce ? "::" : "", function_name);
if (EXPECTED(obj_ce)) {
fcic.function_handler = zend_hash_str_find_ptr(
&obj_ce->function_table, function_name, function_name_len);
if (UNEXPECTED(fcic.function_handler == NULL)) {
/* error at c-level */
zend_error_noreturn(E_CORE_ERROR, "Couldn't find implementation for method %s::%s", ZSTR_VAL(obj_ce->name), function_name);
}
} else {
fcic.function_handler = zend_fetch_function_str(function_name, function_name_len);
if (UNEXPECTED(fcic.function_handler == NULL)) {
/* error at c-level */
zend_error_noreturn(E_CORE_ERROR, "Couldn't find implementation for function %s", function_name);
}
}
if (fn_proxy) {
*fn_proxy = fcic.function_handler;