diff options
| author | jvoisin | 2018-02-05 18:13:57 +0100 |
|---|---|---|
| committer | jvoisin | 2018-02-05 18:13:57 +0100 |
| commit | 9d153cc185b4e2327a4aabe645cf1fabd3b4f21b (patch) | |
| tree | bfaf6ff5fa41098864d6b51ad1fa91304d8c32a6 | |
| parent | 3ab41db5bb38ec534e96f89680e55becd758aa28 (diff) | |
Massive simplification of functions hooking
| -rw-r--r-- | src/sp_config.c | 2 | ||||
| -rw-r--r-- | src/sp_config_keywords.c | 38 | ||||
| -rw-r--r-- | src/sp_cookie_encryption.c | 3 | ||||
| -rw-r--r-- | src/sp_disable_xxe.c | 2 | ||||
| -rw-r--r-- | src/sp_disabled_functions.c | 14 | ||||
| -rw-r--r-- | src/sp_harden_rand.c | 5 | ||||
| -rw-r--r-- | src/sp_pcre_compat.c | 40 | ||||
| -rw-r--r-- | src/sp_unserialize.c | 5 | ||||
| -rw-r--r-- | src/sp_utils.c | 43 | ||||
| -rw-r--r-- | src/sp_utils.h | 13 | ||||
| -rw-r--r-- | src/sp_var_parser.c | 6 | ||||
| -rw-r--r-- | src/tests/config/disabled_functions_retval.ini | 1 |
12 files changed, 83 insertions, 89 deletions
diff --git a/src/sp_config.c b/src/sp_config.c index 1236ebd..67140a0 100644 --- a/src/sp_config.c +++ b/src/sp_config.c | |||
| @@ -141,7 +141,7 @@ int parse_regexp(char *restrict line, char *restrict keyword, void *retval) { | |||
| 141 | 141 | ||
| 142 | if (value) { | 142 | if (value) { |
| 143 | sp_pcre *compiled_re = sp_pcre_compile(value); | 143 | sp_pcre *compiled_re = sp_pcre_compile(value); |
| 144 | if (NULL != compiled_re) { | 144 | if (NULL != compiled_re) { |
| 145 | *(sp_pcre **)retval = compiled_re; | 145 | *(sp_pcre **)retval = compiled_re; |
| 146 | return consumed; | 146 | return consumed; |
| 147 | } | 147 | } |
diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index 5df3d97..959fa38 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c | |||
| @@ -24,8 +24,8 @@ static int get_construct_type(sp_disabled_function const *const df) { | |||
| 24 | return CONSTRUCTS_TYPES[i].type; | 24 | return CONSTRUCTS_TYPES[i].type; |
| 25 | } | 25 | } |
| 26 | } else { | 26 | } else { |
| 27 | if (true == | 27 | if (true == sp_is_regexp_matching(df->r_function, |
| 28 | sp_is_regexp_matching(df->r_function, CONSTRUCTS_TYPES[i].keys[j])) { | 28 | CONSTRUCTS_TYPES[i].keys[j])) { |
| 29 | return CONSTRUCTS_TYPES[i].type; | 29 | return CONSTRUCTS_TYPES[i].type; |
| 30 | } | 30 | } |
| 31 | } | 31 | } |
| @@ -122,13 +122,13 @@ static int parse_eval_filter_conf(char *line, sp_list_node **list) { | |||
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | int parse_eval_blacklist(char *line) { | 124 | int parse_eval_blacklist(char *line) { |
| 125 | return parse_eval_filter_conf(line, | 125 | return parse_eval_filter_conf( |
| 126 | &SNUFFLEUPAGUS_G(config).config_eval->blacklist); | 126 | line, &SNUFFLEUPAGUS_G(config).config_eval->blacklist); |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | int parse_eval_whitelist(char *line) { | 129 | int parse_eval_whitelist(char *line) { |
| 130 | return parse_eval_filter_conf(line, | 130 | return parse_eval_filter_conf( |
| 131 | &SNUFFLEUPAGUS_G(config).config_eval->whitelist); | 131 | line, &SNUFFLEUPAGUS_G(config).config_eval->whitelist); |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | int parse_cookie(char *line) { | 134 | int parse_cookie(char *line) { |
| @@ -204,8 +204,8 @@ int parse_cookie(char *line) { | |||
| 204 | return -1; | 204 | return -1; |
| 205 | } | 205 | } |
| 206 | } | 206 | } |
| 207 | SNUFFLEUPAGUS_G(config).config_cookie->cookies = sp_list_insert( | 207 | SNUFFLEUPAGUS_G(config).config_cookie->cookies = |
| 208 | SNUFFLEUPAGUS_G(config).config_cookie->cookies, cookie); | 208 | sp_list_insert(SNUFFLEUPAGUS_G(config).config_cookie->cookies, cookie); |
| 209 | return SUCCESS; | 209 | return SUCCESS; |
| 210 | } | 210 | } |
| 211 | 211 | ||
| @@ -338,9 +338,9 @@ int parse_disabled_functions(char *line) { | |||
| 338 | 338 | ||
| 339 | if (param) { | 339 | if (param) { |
| 340 | if (strlen(param) > 0 && param[0] != '$') { | 340 | if (strlen(param) > 0 && param[0] != '$') { |
| 341 | /* This is an ugly hack. We're prefixing with a `$` because otherwise | 341 | /* This is an ugly hack. We're prefixing with a `$` because otherwise |
| 342 | * the parser treats this as a constant. | 342 | * the parser treats this as a constant. |
| 343 | * FIXME: Remove this, and improve our (weird) parser. */ | 343 | * FIXME: Remove this, and improve our (weird) parser. */ |
| 344 | char *new = pecalloc(strlen(param) + 2, 1, 1); | 344 | char *new = pecalloc(strlen(param) + 2, 1, 1); |
| 345 | new[0] = '$'; | 345 | new[0] = '$'; |
| 346 | memcpy(new + 1, param, strlen(param)); | 346 | memcpy(new + 1, param, strlen(param)); |
| @@ -372,12 +372,14 @@ int parse_disabled_functions(char *line) { | |||
| 372 | 372 | ||
| 373 | switch (get_construct_type(df)) { | 373 | switch (get_construct_type(df)) { |
| 374 | case ZEND_INCLUDE_OR_EVAL: | 374 | case ZEND_INCLUDE_OR_EVAL: |
| 375 | SNUFFLEUPAGUS_G(config).config_disabled_constructs->construct_include = sp_list_insert( | 375 | SNUFFLEUPAGUS_G(config) |
| 376 | .config_disabled_constructs->construct_include = sp_list_insert( | ||
| 376 | SNUFFLEUPAGUS_G(config).config_disabled_constructs->construct_include, | 377 | SNUFFLEUPAGUS_G(config).config_disabled_constructs->construct_include, |
| 377 | df); | 378 | df); |
| 378 | return ret; | 379 | return ret; |
| 379 | case ZEND_EVAL_CODE: | 380 | case ZEND_EVAL_CODE: |
| 380 | SNUFFLEUPAGUS_G(config).config_disabled_constructs->construct_eval = sp_list_insert( | 381 | SNUFFLEUPAGUS_G(config) |
| 382 | .config_disabled_constructs->construct_eval = sp_list_insert( | ||
| 381 | SNUFFLEUPAGUS_G(config).config_disabled_constructs->construct_eval, | 383 | SNUFFLEUPAGUS_G(config).config_disabled_constructs->construct_eval, |
| 382 | df); | 384 | df); |
| 383 | return ret; | 385 | return ret; |
| @@ -391,11 +393,13 @@ int parse_disabled_functions(char *line) { | |||
| 391 | } | 393 | } |
| 392 | 394 | ||
| 393 | if (df->ret || df->r_ret || df->ret_type) { | 395 | if (df->ret || df->r_ret || df->ret_type) { |
| 394 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret->disabled_functions = sp_list_insert( | 396 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret->disabled_functions = |
| 395 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret->disabled_functions, | 397 | sp_list_insert(SNUFFLEUPAGUS_G(config) |
| 396 | df); | 398 | .config_disabled_functions_ret->disabled_functions, |
| 399 | df); | ||
| 397 | } else { | 400 | } else { |
| 398 | SNUFFLEUPAGUS_G(config).config_disabled_functions->disabled_functions = sp_list_insert( | 401 | SNUFFLEUPAGUS_G(config) |
| 402 | .config_disabled_functions->disabled_functions = sp_list_insert( | ||
| 399 | SNUFFLEUPAGUS_G(config).config_disabled_functions->disabled_functions, | 403 | SNUFFLEUPAGUS_G(config).config_disabled_functions->disabled_functions, |
| 400 | df); | 404 | df); |
| 401 | } | 405 | } |
diff --git a/src/sp_cookie_encryption.c b/src/sp_cookie_encryption.c index 09cf884..4ecb97d 100644 --- a/src/sp_cookie_encryption.c +++ b/src/sp_cookie_encryption.c | |||
| @@ -273,8 +273,7 @@ PHP_FUNCTION(sp_setcookie) { | |||
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | int hook_cookies() { | 275 | int hook_cookies() { |
| 276 | HOOK_FUNCTION("setcookie", sp_internal_functions_hook, PHP_FN(sp_setcookie), | 276 | HOOK_FUNCTION("setcookie", sp_internal_functions_hook, PHP_FN(sp_setcookie)); |
| 277 | false); | ||
| 278 | 277 | ||
| 279 | return SUCCESS; | 278 | return SUCCESS; |
| 280 | } | 279 | } |
diff --git a/src/sp_disable_xxe.c b/src/sp_disable_xxe.c index d11b3d0..df00dbd 100644 --- a/src/sp_disable_xxe.c +++ b/src/sp_disable_xxe.c | |||
| @@ -19,7 +19,7 @@ int hook_libxml_disable_entity_loader() { | |||
| 19 | call_user_function(CG(function_table), NULL, &func_name, &hmac, 1, params); | 19 | call_user_function(CG(function_table), NULL, &func_name, &hmac, 1, params); |
| 20 | 20 | ||
| 21 | HOOK_FUNCTION("libxml_disable_entity_loader", sp_internal_functions_hook, | 21 | HOOK_FUNCTION("libxml_disable_entity_loader", sp_internal_functions_hook, |
| 22 | PHP_FN(sp_libxml_disable_entity_loader), false); | 22 | PHP_FN(sp_libxml_disable_entity_loader)); |
| 23 | 23 | ||
| 24 | return SUCCESS; | 24 | return SUCCESS; |
| 25 | } | 25 | } |
diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c index f8c21d2..eb0ba83 100644 --- a/src/sp_disabled_functions.c +++ b/src/sp_disabled_functions.c | |||
| @@ -258,8 +258,8 @@ bool should_disable(zend_execute_data* execute_data, const char* builtin_name, | |||
| 258 | goto next; | 258 | goto next; |
| 259 | } | 259 | } |
| 260 | } else if (config_node->r_function) { | 260 | } else if (config_node->r_function) { |
| 261 | if (false == | 261 | if (false == sp_is_regexp_matching(config_node->r_function, |
| 262 | sp_is_regexp_matching(config_node->r_function, complete_path_function)) { | 262 | complete_path_function)) { |
| 263 | goto next; | 263 | goto next; |
| 264 | } | 264 | } |
| 265 | } | 265 | } |
| @@ -365,8 +365,8 @@ bool should_drop_on_ret(zval* return_value, | |||
| 365 | goto next; | 365 | goto next; |
| 366 | } | 366 | } |
| 367 | } else if (config_node->r_function) { | 367 | } else if (config_node->r_function) { |
| 368 | if (false == | 368 | if (false == sp_is_regexp_matching(config_node->r_function, |
| 369 | sp_is_regexp_matching(config_node->r_function, complete_path_function)) { | 369 | complete_path_function)) { |
| 370 | goto next; | 370 | goto next; |
| 371 | } | 371 | } |
| 372 | } | 372 | } |
| @@ -445,10 +445,10 @@ static int hook_functions(const sp_list_node* config) { | |||
| 445 | 445 | ||
| 446 | if (NULL != function_name) { // hook function by name | 446 | if (NULL != function_name) { // hook function by name |
| 447 | HOOK_FUNCTION(function_name, disabled_functions_hook, | 447 | HOOK_FUNCTION(function_name, disabled_functions_hook, |
| 448 | PHP_FN(check_disabled_function), false); | 448 | PHP_FN(check_disabled_function)); |
| 449 | } else if (NULL != function_name_regexp) { // hook function by regexp | 449 | } else if (NULL != function_name_regexp) { // hook function by regexp |
| 450 | HOOK_FUNCTION_BY_REGEXP(function_name_regexp, disabled_functions_hook, | 450 | HOOK_FUNCTION_BY_REGEXP(function_name_regexp, disabled_functions_hook, |
| 451 | PHP_FN(check_disabled_function), false); | 451 | PHP_FN(check_disabled_function)); |
| 452 | } else { | 452 | } else { |
| 453 | return FAILURE; | 453 | return FAILURE; |
| 454 | } | 454 | } |
| @@ -505,7 +505,7 @@ int hook_disabled_functions(void) { | |||
| 505 | while (it) { | 505 | while (it) { |
| 506 | hook_function((char*)it->data, | 506 | hook_function((char*)it->data, |
| 507 | SNUFFLEUPAGUS_G(sp_eval_blacklist_functions_hook), | 507 | SNUFFLEUPAGUS_G(sp_eval_blacklist_functions_hook), |
| 508 | PHP_FN(eval_blacklist_callback), false); | 508 | PHP_FN(eval_blacklist_callback)); |
| 509 | it = it->next; | 509 | it = it->next; |
| 510 | } | 510 | } |
| 511 | } | 511 | } |
diff --git a/src/sp_harden_rand.c b/src/sp_harden_rand.c index cb57591..0cb3058 100644 --- a/src/sp_harden_rand.c +++ b/src/sp_harden_rand.c | |||
| @@ -79,9 +79,8 @@ PHP_FUNCTION(sp_mt_rand) { | |||
| 79 | int hook_rand() { | 79 | int hook_rand() { |
| 80 | TSRMLS_FETCH(); | 80 | TSRMLS_FETCH(); |
| 81 | 81 | ||
| 82 | HOOK_FUNCTION("rand", sp_internal_functions_hook, PHP_FN(sp_rand), false); | 82 | HOOK_FUNCTION("rand", sp_internal_functions_hook, PHP_FN(sp_rand)); |
| 83 | HOOK_FUNCTION("mt_rand", sp_internal_functions_hook, PHP_FN(sp_mt_rand), | 83 | HOOK_FUNCTION("mt_rand", sp_internal_functions_hook, PHP_FN(sp_mt_rand)); |
| 84 | false); | ||
| 85 | 84 | ||
| 86 | return SUCCESS; | 85 | return SUCCESS; |
| 87 | } | 86 | } |
diff --git a/src/sp_pcre_compat.c b/src/sp_pcre_compat.c index 42a11cb..c3f1d86 100644 --- a/src/sp_pcre_compat.c +++ b/src/sp_pcre_compat.c | |||
| @@ -2,38 +2,40 @@ | |||
| 2 | 2 | ||
| 3 | #include "sp_pcre_compat.h" | 3 | #include "sp_pcre_compat.h" |
| 4 | 4 | ||
| 5 | sp_pcre* sp_pcre_compile(const char *const pattern) { | 5 | sp_pcre* sp_pcre_compile(const char* const pattern) { |
| 6 | sp_pcre* ret = NULL; | 6 | sp_pcre* ret = NULL; |
| 7 | const char *pcre_error = NULL; | 7 | const char* pcre_error = NULL; |
| 8 | #ifdef SP_HAS_PCRE2 | 8 | #ifdef SP_HAS_PCRE2 |
| 9 | int errornumber; | 9 | int errornumber; |
| 10 | PCRE2_SIZE erroroffset; | 10 | PCRE2_SIZE erroroffset; |
| 11 | ret = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &errornumber, &erroroffset, NULL); | 11 | ret = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, |
| 12 | PCRE2_CASELESS, &errornumber, &erroroffset, NULL); | ||
| 12 | #else | 13 | #else |
| 13 | int erroroffset; | 14 | int erroroffset; |
| 14 | ret = pcre_compile(pattern, PCRE_CASELESS, &pcre_error, &erroroffset, NULL); | 15 | ret = pcre_compile(pattern, PCRE_CASELESS, &pcre_error, &erroroffset, NULL); |
| 15 | #endif | 16 | #endif |
| 16 | 17 | ||
| 17 | if (NULL == ret) { | 18 | if (NULL == ret) { |
| 18 | sp_log_err("config", "Failed to compile '%s': %s on line %zu.", pattern, | 19 | sp_log_err("config", "Failed to compile '%s': %s on line %zu.", pattern, |
| 19 | pcre_error, sp_line_no); | 20 | pcre_error, sp_line_no); |
| 20 | } | 21 | } |
| 21 | return ret; | 22 | return ret; |
| 22 | } | 23 | } |
| 23 | 24 | ||
| 24 | bool sp_is_regexp_matching_len(const sp_pcre* regexp, const char* str, size_t len) { | 25 | bool sp_is_regexp_matching_len(const sp_pcre* regexp, const char* str, |
| 26 | size_t len) { | ||
| 25 | int ret = 0; | 27 | int ret = 0; |
| 26 | 28 | ||
| 27 | assert(NULL != regexp); | 29 | assert(NULL != regexp); |
| 28 | assert(NULL != str); | 30 | assert(NULL != str); |
| 29 | 31 | ||
| 30 | #ifdef SP_HAS_PCRE2 | 32 | #ifdef SP_HAS_PCRE2 |
| 31 | pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(regexp, NULL); | 33 | pcre2_match_data* match_data = |
| 32 | ret = pcre2_match(regexp, (PCRE2_SPTR)str, len, 0, 0, match_data, NULL); | 34 | pcre2_match_data_create_from_pattern(regexp, NULL); |
| 35 | ret = pcre2_match(regexp, (PCRE2_SPTR)str, len, 0, 0, match_data, NULL); | ||
| 33 | #else | 36 | #else |
| 34 | int vec[30]; | 37 | int vec[30]; |
| 35 | ret = pcre_exec(regexp, NULL, str, len, 0, 0, vec, | 38 | ret = pcre_exec(regexp, NULL, str, len, 0, 0, vec, sizeof(vec) / sizeof(int)); |
| 36 | sizeof(vec) / sizeof(int)); | ||
| 37 | #endif | 39 | #endif |
| 38 | 40 | ||
| 39 | if (ret < 0) { | 41 | if (ret < 0) { |
diff --git a/src/sp_unserialize.c b/src/sp_unserialize.c index 6b7b03b..a1dbbee 100644 --- a/src/sp_unserialize.c +++ b/src/sp_unserialize.c | |||
| @@ -102,10 +102,9 @@ PHP_FUNCTION(sp_unserialize) { | |||
| 102 | int hook_serialize(void) { | 102 | int hook_serialize(void) { |
| 103 | TSRMLS_FETCH(); | 103 | TSRMLS_FETCH(); |
| 104 | 104 | ||
| 105 | HOOK_FUNCTION("serialize", sp_internal_functions_hook, PHP_FN(sp_serialize), | 105 | HOOK_FUNCTION("serialize", sp_internal_functions_hook, PHP_FN(sp_serialize)); |
| 106 | false); | ||
| 107 | HOOK_FUNCTION("unserialize", sp_internal_functions_hook, | 106 | HOOK_FUNCTION("unserialize", sp_internal_functions_hook, |
| 108 | PHP_FN(sp_unserialize), false); | 107 | PHP_FN(sp_unserialize)); |
| 109 | 108 | ||
| 110 | return SUCCESS; | 109 | return SUCCESS; |
| 111 | } | 110 | } |
diff --git a/src/sp_utils.c b/src/sp_utils.c index 2979d98..8dbd14e 100644 --- a/src/sp_utils.c +++ b/src/sp_utils.c | |||
| @@ -173,7 +173,8 @@ char* sp_convert_to_string(zval* zv) { | |||
| 173 | return estrdup(""); | 173 | return estrdup(""); |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | bool sp_match_value(const char* value, const char* to_match, const sp_pcre* rx) { | 176 | bool sp_match_value(const char* value, const char* to_match, |
| 177 | const sp_pcre* rx) { | ||
| 177 | if (to_match) { | 178 | if (to_match) { |
| 178 | if (0 == strcmp(to_match, value)) { | 179 | if (0 == strcmp(to_match, value)) { |
| 179 | return true; | 180 | return true; |
| @@ -255,7 +256,8 @@ void sp_log_disable_ret(const char* restrict path, | |||
| 255 | } | 256 | } |
| 256 | } | 257 | } |
| 257 | 258 | ||
| 258 | bool sp_match_array_key(const zval* zv, const char* to_match, const sp_pcre* rx) { | 259 | bool sp_match_array_key(const zval* zv, const char* to_match, |
| 260 | const sp_pcre* rx) { | ||
| 259 | zend_string* key; | 261 | zend_string* key; |
| 260 | zend_ulong idx; | 262 | zend_ulong idx; |
| 261 | 263 | ||
| @@ -300,16 +302,14 @@ bool sp_match_array_value(const zval* arr, const char* to_match, | |||
| 300 | } | 302 | } |
| 301 | 303 | ||
| 302 | int hook_function(const char* original_name, HashTable* hook_table, | 304 | int hook_function(const char* original_name, HashTable* hook_table, |
| 303 | void (*new_function)(INTERNAL_FUNCTION_PARAMETERS), | 305 | void (*new_function)(INTERNAL_FUNCTION_PARAMETERS)) { |
| 304 | bool hook_execution_table) { | ||
| 305 | zend_internal_function* func; | 306 | zend_internal_function* func; |
| 306 | HashTable* ht = | ||
| 307 | hook_execution_table == true ? EG(function_table) : CG(function_table); | ||
| 308 | 307 | ||
| 309 | /* The `mb` module likes to hook functions, like strlen->mb_strlen, | 308 | /* The `mb` module likes to hook functions, like strlen->mb_strlen, |
| 310 | * so we have to hook both of them. */ | 309 | * so we have to hook both of them. */ |
| 311 | 310 | ||
| 312 | if ((func = zend_hash_str_find_ptr(ht, VAR_AND_LEN(original_name)))) { | 311 | if ((func = zend_hash_str_find_ptr(CG(function_table), |
| 312 | VAR_AND_LEN(original_name)))) { | ||
| 313 | if (func->handler == new_function) { | 313 | if (func->handler == new_function) { |
| 314 | return SUCCESS; | 314 | return SUCCESS; |
| 315 | } | 315 | } |
| @@ -332,9 +332,9 @@ int hook_function(const char* original_name, HashTable* hook_table, | |||
| 332 | 332 | ||
| 333 | if (0 == strncmp(original_name, "mb_", 3)) { | 333 | if (0 == strncmp(original_name, "mb_", 3)) { |
| 334 | CG(compiler_options) |= ZEND_COMPILE_NO_BUILTIN_STRLEN; | 334 | CG(compiler_options) |= ZEND_COMPILE_NO_BUILTIN_STRLEN; |
| 335 | if (zend_hash_str_find(ht, VAR_AND_LEN(original_name + 3))) { | 335 | if (zend_hash_str_find(CG(function_table), |
| 336 | hook_function(original_name + 3, hook_table, new_function, | 336 | VAR_AND_LEN(original_name + 3))) { |
| 337 | hook_execution_table); | 337 | hook_function(original_name + 3, hook_table, new_function); |
| 338 | } | 338 | } |
| 339 | } else { // TODO this can be moved somewhere else to gain some marginal perfs | 339 | } else { // TODO this can be moved somewhere else to gain some marginal perfs |
| 340 | CG(compiler_options) |= ZEND_COMPILE_NO_BUILTIN_STRLEN; | 340 | CG(compiler_options) |= ZEND_COMPILE_NO_BUILTIN_STRLEN; |
| @@ -342,7 +342,7 @@ int hook_function(const char* original_name, HashTable* hook_table, | |||
| 342 | memcpy(mb_name, "mb_", 3); | 342 | memcpy(mb_name, "mb_", 3); |
| 343 | memcpy(mb_name + 3, VAR_AND_LEN(original_name)); | 343 | memcpy(mb_name + 3, VAR_AND_LEN(original_name)); |
| 344 | if (zend_hash_str_find(CG(function_table), VAR_AND_LEN(mb_name))) { | 344 | if (zend_hash_str_find(CG(function_table), VAR_AND_LEN(mb_name))) { |
| 345 | hook_function(mb_name, hook_table, new_function, hook_execution_table); | 345 | hook_function(mb_name, hook_table, new_function); |
| 346 | } | 346 | } |
| 347 | } | 347 | } |
| 348 | 348 | ||
| @@ -350,26 +350,17 @@ int hook_function(const char* original_name, HashTable* hook_table, | |||
| 350 | } | 350 | } |
| 351 | 351 | ||
| 352 | int hook_regexp(const sp_pcre* regexp, HashTable* hook_table, | 352 | int hook_regexp(const sp_pcre* regexp, HashTable* hook_table, |
| 353 | void (*new_function)(INTERNAL_FUNCTION_PARAMETERS), | 353 | void (*new_function)(INTERNAL_FUNCTION_PARAMETERS)) { |
| 354 | bool hook_execution_table) { | ||
| 355 | zend_string* key; | 354 | zend_string* key; |
| 356 | HashTable* ht = | ||
| 357 | hook_execution_table == true ? EG(function_table) : CG(function_table); | ||
| 358 | 355 | ||
| 359 | ZEND_HASH_FOREACH_STR_KEY(ht, key) { | 356 | ZEND_HASH_FOREACH_STR_KEY(CG(function_table), key) |
| 360 | if (key) { | 357 | if (key) { |
| 361 | int ret = sp_is_regexp_matching_len(regexp, key->val, key->len); | 358 | if (true == sp_is_regexp_matching_len(regexp, key->val, key->len)) { |
| 362 | if (ret < 0) { /* Error or no match*/ | 359 | hook_function(key->val, hook_table, new_function); |
| 363 | if (PCRE_ERROR_NOMATCH != ret) { | ||
| 364 | sp_log_err("pcre", "Runtime error with pcre, error code: %d", ret); | ||
| 365 | return FAILURE; | ||
| 366 | } | ||
| 367 | continue; | ||
| 368 | } | ||
| 369 | hook_function(key->val, hook_table, new_function, hook_execution_table); | ||
| 370 | } | 360 | } |
| 371 | } | 361 | } |
| 372 | ZEND_HASH_FOREACH_END(); | 362 | ZEND_HASH_FOREACH_END(); |
| 363 | |||
| 373 | return SUCCESS; | 364 | return SUCCESS; |
| 374 | } | 365 | } |
| 375 | 366 | ||
diff --git a/src/sp_utils.h b/src/sp_utils.h index 10a6daa..97808ad 100644 --- a/src/sp_utils.h +++ b/src/sp_utils.h | |||
| @@ -22,12 +22,11 @@ | |||
| 22 | 22 | ||
| 23 | #define SHA256_SIZE 32 | 23 | #define SHA256_SIZE 32 |
| 24 | 24 | ||
| 25 | #define HOOK_FUNCTION(original_name, hook_table, new_function, execution) \ | 25 | #define HOOK_FUNCTION(original_name, hook_table, new_function) \ |
| 26 | hook_function(original_name, SNUFFLEUPAGUS_G(hook_table), new_function, \ | 26 | hook_function(original_name, SNUFFLEUPAGUS_G(hook_table), new_function) |
| 27 | execution) | ||
| 28 | 27 | ||
| 29 | #define HOOK_FUNCTION_BY_REGEXP(regexp, hook_table, new_function, execution) \ | 28 | #define HOOK_FUNCTION_BY_REGEXP(regexp, hook_table, new_function) \ |
| 30 | hook_regexp(regexp, SNUFFLEUPAGUS_G(hook_table), new_function, execution) | 29 | hook_regexp(regexp, SNUFFLEUPAGUS_G(hook_table), new_function) |
| 31 | 30 | ||
| 32 | #define SP_LOG_SIMULATION "simulation" | 31 | #define SP_LOG_SIMULATION "simulation" |
| 33 | #define SP_LOG_DROP "drop" | 32 | #define SP_LOG_DROP "drop" |
| @@ -54,9 +53,9 @@ void sp_log_disable(const char *restrict, const char *restrict, | |||
| 54 | void sp_log_disable_ret(const char *restrict, const char *restrict, | 53 | void sp_log_disable_ret(const char *restrict, const char *restrict, |
| 55 | const sp_disabled_function *); | 54 | const sp_disabled_function *); |
| 56 | int hook_function(const char *, HashTable *, | 55 | int hook_function(const char *, HashTable *, |
| 57 | void (*)(INTERNAL_FUNCTION_PARAMETERS), bool); | 56 | void (*)(INTERNAL_FUNCTION_PARAMETERS)); |
| 58 | int hook_regexp(const sp_pcre *, HashTable *, | 57 | int hook_regexp(const sp_pcre *, HashTable *, |
| 59 | void (*)(INTERNAL_FUNCTION_PARAMETERS), bool); | 58 | void (*)(INTERNAL_FUNCTION_PARAMETERS)); |
| 60 | bool check_is_in_eval_whitelist(const char * const function_name); | 59 | bool check_is_in_eval_whitelist(const char * const function_name); |
| 61 | 60 | ||
| 62 | #endif /* SP_UTILS_H */ | 61 | #endif /* SP_UTILS_H */ |
diff --git a/src/sp_var_parser.c b/src/sp_var_parser.c index 330fa54..ab36677 100644 --- a/src/sp_var_parser.c +++ b/src/sp_var_parser.c | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | #include "php_snuffleupagus.h" | 1 | #include "php_snuffleupagus.h" |
| 2 | 2 | ||
| 3 | static sp_list_node *parse_str_tokens(const char *str, const sp_conf_token token, | 3 | static sp_list_node *parse_str_tokens(const char *str, |
| 4 | sp_list_node *tokens_list) { | 4 | const sp_conf_token token, |
| 5 | sp_list_node *tokens_list) { | ||
| 5 | const char *cur_str = str; | 6 | const char *cur_str = str; |
| 6 | 7 | ||
| 7 | while ((cur_str = strchr(cur_str, token.text_repr[0]))) { | 8 | while ((cur_str = strchr(cur_str, token.text_repr[0]))) { |
| @@ -31,7 +32,6 @@ static bool is_var_name_valid(const char *name) { | |||
| 31 | regexp_const = sp_pcre_compile(REGEXP_CONST); | 32 | regexp_const = sp_pcre_compile(REGEXP_CONST); |
| 32 | } | 33 | } |
| 33 | if (NULL == regexp_var || NULL == regexp_const) { | 34 | if (NULL == regexp_var || NULL == regexp_const) { |
| 34 | sp_log_err("config", "Could not compile regexp."); | ||
| 35 | return false; | 35 | return false; |
| 36 | } | 36 | } |
| 37 | if ((false == sp_is_regexp_matching(regexp_var, name)) && | 37 | if ((false == sp_is_regexp_matching(regexp_var, name)) && |
diff --git a/src/tests/config/disabled_functions_retval.ini b/src/tests/config/disabled_functions_retval.ini index b54c0fa..25a99f0 100644 --- a/src/tests/config/disabled_functions_retval.ini +++ b/src/tests/config/disabled_functions_retval.ini | |||
| @@ -1 +1,2 @@ | |||
| 1 | sp.disable_function.function("str_repeat").ret("fufufu").filename("/var/www/test.php").drop(); | ||
| 1 | sp.disable_function.function("str_repeat").ret("fufufu").drop(); | 2 | sp.disable_function.function("str_repeat").ret("fufufu").drop(); |
