From 050eefd845ed9a588a8c92ed10827b0669883145 Mon Sep 17 00:00:00 2001 From: xXx-caillou-xXx Date: Fri, 13 Jul 2018 15:59:19 +0200 Subject: Reduce call to get_complete_function_path --- src/sp_disabled_functions.c | 40 ++++++++++------------------------ src/sp_disabled_functions.h | 6 +++-- src/sp_execute.c | 14 +++++++++--- src/tests/disabled_functions_ret3.phpt | 2 -- 4 files changed, 27 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c index f6e06e4..2e459a9 100644 --- a/src/sp_disabled_functions.c +++ b/src/sp_disabled_functions.c @@ -250,11 +250,10 @@ static bool check_is_builtin_name( } bool should_disable_ht(zend_execute_data* execute_data, - const char* builtin_name, + const char* function_name, const zend_string* builtin_param, const char* builtin_param_name, const sp_list_node* config, const HashTable* ht) { - char* complete_function_path = NULL; const sp_list_node* ht_entry = NULL; bool ret = false; zend_string* current_filename; @@ -263,35 +262,24 @@ bool should_disable_ht(zend_execute_data* execute_data, return false; } - if (builtin_name) { - complete_function_path = estrdup(builtin_name); - } else { - complete_function_path = get_complete_function_path(execute_data); - if (!complete_function_path) { - return false; - } - } - - if (UNEXPECTED(builtin_param && !strcmp(complete_function_path, "eval"))) { + if (UNEXPECTED(builtin_param && !strcmp(function_name, "eval"))) { current_filename = get_eval_filename(zend_get_executed_filename()); } else { const char* tmp = zend_get_executed_filename(); current_filename = zend_string_init(tmp, strlen(tmp), 0); } - ht_entry = zend_hash_str_find_ptr(ht, complete_function_path, - strlen(complete_function_path)); + ht_entry = zend_hash_str_find_ptr(ht, function_name, strlen(function_name)); if (ht_entry && - should_disable(execute_data, complete_function_path, builtin_param, + should_disable(execute_data, function_name, builtin_param, builtin_param_name, ht_entry, current_filename)) { ret = true; } else if (config && config->data) { - ret = should_disable(execute_data, complete_function_path, builtin_param, + ret = should_disable(execute_data, function_name, builtin_param, builtin_param_name, config, current_filename); } - efree(complete_function_path); efree(current_filename); return ret; } @@ -423,28 +411,24 @@ allow: return false; } -bool should_drop_on_ret_ht(zval* return_value, - const zend_execute_data* const execute_data, +bool should_drop_on_ret_ht(zval* return_value, const char* function_name, const sp_list_node* config, const HashTable* ht) { - char* complete_function_path = get_complete_function_path(execute_data); const sp_list_node* ht_entry = NULL; bool ret = false; - if (!complete_function_path) { + if (!function_name) { return ret; } - ht_entry = zend_hash_str_find_ptr(ht, complete_function_path, - strlen(complete_function_path)); + ht_entry = zend_hash_str_find_ptr(ht, function_name, strlen(function_name)); if (ht_entry && - should_drop_on_ret(return_value, ht_entry, complete_function_path)) { + should_drop_on_ret(return_value, ht_entry, function_name)) { ret = true; } else if (config && config->data) { - ret = should_drop_on_ret(return_value, config, complete_function_path); + ret = should_drop_on_ret(return_value, config, function_name); } - efree(complete_function_path); return ret; } @@ -522,7 +506,7 @@ ZEND_FUNCTION(check_disabled_function) { const char* current_function_name = get_active_function_name(TSRMLS_C); if (true == should_disable_ht( - execute_data, NULL, NULL, NULL, + execute_data, current_function_name, NULL, NULL, SNUFFLEUPAGUS_G(config) .config_disabled_functions_reg->disabled_functions, SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked)) { @@ -535,7 +519,7 @@ ZEND_FUNCTION(check_disabled_function) { orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); if (true == should_drop_on_ret_ht( - return_value, execute_data, + return_value, current_function_name, SNUFFLEUPAGUS_G(config) .config_disabled_functions_reg_ret->disabled_functions, SNUFFLEUPAGUS_G(config).config_disabled_functions_ret_hooked)) { diff --git a/src/sp_disabled_functions.h b/src/sp_disabled_functions.h index 83b1551..4e9f7ad 100644 --- a/src/sp_disabled_functions.h +++ b/src/sp_disabled_functions.h @@ -8,8 +8,10 @@ int hook_echo(const char*, size_t); bool should_disable(zend_execute_data *, const char *, const zend_string *, const char *, const sp_list_node *, const zend_string *); bool should_disable_ht(zend_execute_data *, const char *, const zend_string *, - const char *, const sp_list_node *, const HashTable *); -bool should_drop_on_ret_ht(zval *, const zend_execute_data *const, const sp_list_node* config, const HashTable *); + const char *, const sp_list_node *, const HashTable *); +bool should_drop_on_ret_ht(zval *, const char *, const sp_list_node* config, + const HashTable *); bool should_drop_on_ret(zval *, const sp_list_node* config, const char *); +char* get_complete_function_path(zend_execute_data const* const); #endif /* __SP_DISABLE_FUNCTIONS_H */ diff --git a/src/sp_execute.c b/src/sp_execute.c index 6e38c75..96d9d85 100644 --- a/src/sp_execute.c +++ b/src/sp_execute.c @@ -150,13 +150,20 @@ static void sp_execute_ex(zend_execute_data *execute_data) { } if (SNUFFLEUPAGUS_G(config).hook_execute) { + char* function_name = get_complete_function_path(execute_data); + + if (!function_name) { + orig_execute_ex(execute_data); + 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_ht( - execute_data, NULL, NULL, NULL, + execute_data, function_name, NULL, NULL, SNUFFLEUPAGUS_G(config) .config_disabled_functions_reg->disabled_functions, SNUFFLEUPAGUS_G(config).config_disabled_functions))) { @@ -170,7 +177,7 @@ static void sp_execute_ex(zend_execute_data *execute_data) { ZEND_DO_FCALL_BY_NAME)) { if (UNEXPECTED(true == should_disable_ht( - execute_data, NULL, NULL, NULL, + execute_data, function_name, NULL, NULL, SNUFFLEUPAGUS_G(config) .config_disabled_functions_reg->disabled_functions, SNUFFLEUPAGUS_G(config).config_disabled_functions))) { @@ -183,12 +190,13 @@ static void sp_execute_ex(zend_execute_data *execute_data) { if (UNEXPECTED( true == should_drop_on_ret_ht( - EX(return_value), execute_data, + EX(return_value), function_name, SNUFFLEUPAGUS_G(config) .config_disabled_functions_reg_ret->disabled_functions, SNUFFLEUPAGUS_G(config).config_disabled_functions_ret))) { sp_terminate(); } + efree(function_name); } else { orig_execute_ex(execute_data); } diff --git a/src/tests/disabled_functions_ret3.phpt b/src/tests/disabled_functions_ret3.phpt index 87af0d3..87a44ef 100644 --- a/src/tests/disabled_functions_ret3.phpt +++ b/src/tests/disabled_functions_ret3.phpt @@ -20,5 +20,3 @@ echo("We're at the end of the execution.\n"); --EXPECTF-- We're in function `a`. [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on return of the function 'Bob::a' in %a/disabled_functions_ret3.php:9, because the function returned '2', which matched a rule. ---XFAIL-- -Match on ret is broken for non-native functions :/ -- cgit v1.3