From 83ba52143d0da9050811d4566b2b77c1b03b0079 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 8 Mar 2018 10:58:46 +0100 Subject: Marginally improve the performances when dealing with eval --- src/sp_execute.c | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) (limited to 'src/sp_execute.c') diff --git a/src/sp_execute.c b/src/sp_execute.c index bb9f64e..bb03ad9 100644 --- a/src/sp_execute.c +++ b/src/sp_execute.c @@ -35,10 +35,10 @@ ZEND_COLD static inline void terminate_if_writable(const char *filename) { } } -static void is_builtin_matching(const char *restrict const filename, - const char *restrict const function_name, - const char *restrict const param_name, - const sp_list_node *config) { +static void inline is_builtin_matching(const char *restrict const filename, + const char *restrict const function_name, + const char *restrict const param_name, + const sp_list_node *config) { if (!config || !config->data) { return; } @@ -121,31 +121,37 @@ static void sp_execute_ex(zend_execute_data *execute_data) { if (!execute_data) { return; - } else if (!execute_data->prev_execute_data || - !execute_data->prev_execute_data->func || - !ZEND_USER_CODE(execute_data->prev_execute_data->func->type) || - !execute_data->prev_execute_data->opline) { - if (UNEXPECTED(true == should_disable(execute_data, NULL, NULL, NULL))) { - sp_terminate(); - } - } else if (execute_data->prev_execute_data != NULL) { - if ((execute_data->prev_execute_data->opline->opcode == ZEND_DO_FCALL || - execute_data->prev_execute_data->opline->opcode == ZEND_DO_UCALL || - execute_data->prev_execute_data->opline->opcode == - ZEND_DO_FCALL_BY_NAME)) { - if (UNEXPECTED(true == should_disable(execute_data, NULL, NULL, NULL))) { - sp_terminate(); - } - } } if (UNEXPECTED(EX(func)->op_array.type == ZEND_EVAL_CODE)) { - SNUFFLEUPAGUS_G(in_eval)++; const sp_list_node *config = SNUFFLEUPAGUS_G(config).config_disabled_constructs->construct_eval; char *filename = get_eval_filename((char *)zend_get_executed_filename()); is_builtin_matching(filename, "eval", NULL, config); efree(filename); + + SNUFFLEUPAGUS_G(in_eval)++; + orig_execute_ex(execute_data); + SNUFFLEUPAGUS_G(in_eval)--; + return; + } + + if (!execute_data->prev_execute_data || + !execute_data->prev_execute_data->func || + !ZEND_USER_CODE(execute_data->prev_execute_data->func->type) || + !execute_data->prev_execute_data->opline) { + if (UNEXPECTED(true == should_disable(execute_data, NULL, NULL, NULL))) { + sp_terminate(); + } + } else if ((execute_data->prev_execute_data->opline->opcode == + ZEND_DO_FCALL || + execute_data->prev_execute_data->opline->opcode == + ZEND_DO_UCALL || + execute_data->prev_execute_data->opline->opcode == + ZEND_DO_FCALL_BY_NAME)) { + if (UNEXPECTED(true == should_disable(execute_data, NULL, NULL, NULL))) { + sp_terminate(); + } } if (NULL != EX(func)->op_array.filename) { @@ -159,10 +165,6 @@ static void sp_execute_ex(zend_execute_data *execute_data) { if (UNEXPECTED(true == should_drop_on_ret(EX(return_value), execute_data))) { sp_terminate(); } - - if (UNEXPECTED(ZEND_EVAL_CODE == EX(func)->op_array.type)) { - SNUFFLEUPAGUS_G(in_eval)--; - } } static void sp_zend_execute_internal(INTERNAL_FUNCTION_PARAMETERS) { -- cgit v1.3