diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/sp_disabled_functions.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c index e4ba19a..7c079fb 100644 --- a/src/sp_disabled_functions.c +++ b/src/sp_disabled_functions.c | |||
| @@ -5,17 +5,9 @@ | |||
| 5 | 5 | ||
| 6 | ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus); | 6 | ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus); |
| 7 | 7 | ||
| 8 | ZEND_COLD static zend_always_inline bool is_hash_matching( | ||
| 9 | const char* current_filename, | ||
| 10 | sp_disabled_function const* const config_node) { | ||
| 11 | char current_file_hash[SHA256_SIZE * 2]; | ||
| 12 | compute_hash(current_filename, current_file_hash); | ||
| 13 | return (0 == strncmp(current_file_hash, config_node->hash, SHA256_SIZE)); | ||
| 14 | } | ||
| 15 | |||
| 16 | static zend_always_inline char* get_complete_function_path( | 8 | static zend_always_inline char* get_complete_function_path( |
| 17 | zend_execute_data const* const execute_data) { | 9 | zend_execute_data const* const execute_data) { |
| 18 | 10 | ||
| 19 | if (!(execute_data->func->common.function_name)) { | 11 | if (!(execute_data->func->common.function_name)) { |
| 20 | return NULL; | 12 | return NULL; |
| 21 | } | 13 | } |
| @@ -40,7 +32,7 @@ static bool is_functions_list_matching(zend_execute_data *execute_data, sp_node_ | |||
| 40 | zend_execute_data *orig_execute_data, *current; | 32 | zend_execute_data *orig_execute_data, *current; |
| 41 | orig_execute_data = current = execute_data; | 33 | orig_execute_data = current = execute_data; |
| 42 | sp_node_t *it = functions_list; | 34 | sp_node_t *it = functions_list; |
| 43 | 35 | ||
| 44 | while (current) { | 36 | while (current) { |
| 45 | if (it == NULL) { // every function in the list matched, we've got a match! | 37 | if (it == NULL) { // every function in the list matched, we've got a match! |
| 46 | EG(current_execute_data) = orig_execute_data; | 38 | EG(current_execute_data) = orig_execute_data; |
| @@ -71,12 +63,12 @@ end: | |||
| 71 | 63 | ||
| 72 | static bool is_local_var_matching(zend_execute_data *execute_data, const sp_disabled_function *const config_node) { | 64 | static bool is_local_var_matching(zend_execute_data *execute_data, const sp_disabled_function *const config_node) { |
| 73 | zend_execute_data *orig_execute_data = execute_data; | 65 | zend_execute_data *orig_execute_data = execute_data; |
| 74 | 66 | ||
| 75 | /*because execute_data points to hooked function data, | 67 | /*because execute_data points to hooked function data, |
| 76 | which we dont care about */ | 68 | which we dont care about */ |
| 77 | zend_execute_data *current = execute_data->prev_execute_data; | 69 | zend_execute_data *current = execute_data->prev_execute_data; |
| 78 | zval *value = NULL; | 70 | zval *value = NULL; |
| 79 | 71 | ||
| 80 | while (current) { | 72 | while (current) { |
| 81 | zend_string *key = NULL; | 73 | zend_string *key = NULL; |
| 82 | EG(current_execute_data) = current; | 74 | EG(current_execute_data) = current; |
| @@ -110,6 +102,7 @@ static bool is_local_var_matching(zend_execute_data *execute_data, const sp_disa | |||
| 110 | } | 102 | } |
| 111 | 103 | ||
| 112 | bool should_disable(zend_execute_data* execute_data) { | 104 | bool should_disable(zend_execute_data* execute_data) { |
| 105 | char current_file_hash[SHA256_SIZE * 2] = {0}; | ||
| 113 | const char* current_filename = zend_get_executed_filename(TSRMLS_C); | 106 | const char* current_filename = zend_get_executed_filename(TSRMLS_C); |
| 114 | const sp_node_t* config = | 107 | const sp_node_t* config = |
| 115 | SNUFFLEUPAGUS_G(config).config_disabled_functions->disabled_functions; | 108 | SNUFFLEUPAGUS_G(config).config_disabled_functions->disabled_functions; |
| @@ -174,7 +167,10 @@ bool should_disable(zend_execute_data* execute_data) { | |||
| 174 | } | 167 | } |
| 175 | 168 | ||
| 176 | if (config_node->hash) { | 169 | if (config_node->hash) { |
| 177 | if (false == is_hash_matching(current_filename, config_node)) { | 170 | if ('\0' == current_file_hash[0]) { |
| 171 | compute_hash(current_filename, current_file_hash); | ||
| 172 | } | ||
| 173 | if (0 != strncmp(current_file_hash, config_node->hash, SHA256_SIZE)) { | ||
| 178 | goto next; | 174 | goto next; |
| 179 | } | 175 | } |
| 180 | } | 176 | } |
| @@ -280,6 +276,7 @@ static bool should_drop_on_ret(zval* return_value, | |||
| 280 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret->disabled_functions; | 276 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret->disabled_functions; |
| 281 | char* complete_path_function = get_complete_function_path(execute_data); | 277 | char* complete_path_function = get_complete_function_path(execute_data); |
| 282 | const char* current_filename = zend_get_executed_filename(TSRMLS_C); | 278 | const char* current_filename = zend_get_executed_filename(TSRMLS_C); |
| 279 | char current_file_hash[SHA256_SIZE * 2] = {0}; | ||
| 283 | 280 | ||
| 284 | if (!config || !config->data) { | 281 | if (!config || !config->data) { |
| 285 | return false; | 282 | return false; |
| @@ -317,7 +314,10 @@ static bool should_drop_on_ret(zval* return_value, | |||
| 317 | } | 314 | } |
| 318 | 315 | ||
| 319 | if (config_node->hash) { | 316 | if (config_node->hash) { |
| 320 | if (false == is_hash_matching(current_filename, config_node)) { | 317 | if ('\0' == current_file_hash[0]) { |
| 318 | compute_hash(current_filename, current_file_hash); | ||
| 319 | } | ||
| 320 | if (0 != strncmp(current_file_hash, config_node->hash, SHA256_SIZE)) { | ||
| 321 | goto next; | 321 | goto next; |
| 322 | } | 322 | } |
| 323 | } | 323 | } |
