From 467f965bf178b1c4d60ddac87af14718f6013bab Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 30 Jan 2021 21:19:29 +0100 Subject: Improve a bit type diversity --- src/sp_disabled_functions.c | 17 +++++++---------- src/sp_utils.c | 8 ++++---- src/sp_utils.h | 2 +- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c index 41c9f23..6a559c8 100644 --- a/src/sp_disabled_functions.c +++ b/src/sp_disabled_functions.c @@ -532,13 +532,13 @@ static int hook_functions_regexp(const sp_list_node* config) { return SUCCESS; } -static int hook_functions(HashTable* to_hook_ht, HashTable* hooked_ht) { +static void hook_functions(HashTable* to_hook_ht, HashTable* hooked_ht) { zend_string* key; zval* value; ZEND_HASH_FOREACH_STR_KEY_VAL(to_hook_ht, key, value) { - bool hooked = !HOOK_FUNCTION(ZSTR_VAL(key), disabled_functions_hook, - PHP_FN(check_disabled_function)); + bool hooked = HOOK_FUNCTION(ZSTR_VAL(key), disabled_functions_hook, + PHP_FN(check_disabled_function)); bool is_builtin = check_is_builtin_name(((sp_list_node*)Z_PTR_P(value))->data); if (hooked || is_builtin) { @@ -547,7 +547,6 @@ static int hook_functions(HashTable* to_hook_ht, HashTable* hooked_ht) { } } ZEND_HASH_FOREACH_END(); - return SUCCESS; } ZEND_FUNCTION(eval_blacklist_callback) { @@ -595,13 +594,11 @@ int hook_disabled_functions(void) { int ret = SUCCESS; - ret |= - hook_functions(SNUFFLEUPAGUS_G(config).config_disabled_functions, - SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked); + hook_functions(SNUFFLEUPAGUS_G(config).config_disabled_functions, + SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked); - ret |= hook_functions( - SNUFFLEUPAGUS_G(config).config_disabled_functions_ret, - SNUFFLEUPAGUS_G(config).config_disabled_functions_ret_hooked); + hook_functions(SNUFFLEUPAGUS_G(config).config_disabled_functions_ret, + SNUFFLEUPAGUS_G(config).config_disabled_functions_ret_hooked); ret |= hook_functions_regexp( SNUFFLEUPAGUS_G(config) diff --git a/src/sp_utils.c b/src/sp_utils.c index 147cc46..a7a3d27 100644 --- a/src/sp_utils.c +++ b/src/sp_utils.c @@ -394,10 +394,10 @@ bool sp_match_array_value(const zval* arr, const zend_string* to_match, return false; } -int hook_function(const char* original_name, HashTable* hook_table, - zif_handler new_function) { +bool hook_function(const char* original_name, HashTable* hook_table, + zif_handler new_function) { zend_internal_function* func; - bool ret = FAILURE; + bool ret = false; /* The `mb` module likes to hook functions, like strlen->mb_strlen, * so we have to hook both of them. */ @@ -416,7 +416,7 @@ int hook_function(const char* original_name, HashTable* hook_table, // LCOV_EXCL_STOP } func->handler = new_function; - ret = SUCCESS; + ret = true; } } diff --git a/src/sp_utils.h b/src/sp_utils.h index a883d6d..081f786 100644 --- a/src/sp_utils.h +++ b/src/sp_utils.h @@ -72,7 +72,7 @@ void sp_log_disable(const char *restrict, const char *restrict, const zend_string *restrict, const sp_disabled_function *); void sp_log_disable_ret(const char *restrict, const zend_string *restrict, const sp_disabled_function *); -int hook_function(const char *, HashTable *, zif_handler); +bool hook_function(const char *, HashTable *, zif_handler); int hook_regexp(const sp_pcre *, HashTable *, zif_handler); bool check_is_in_eval_whitelist(const zend_string *const function_name); int sp_log_request(const zend_string *restrict folder, -- cgit v1.3