summaryrefslogtreecommitdiff
path: root/src/sp_disabled_functions.c
diff options
context:
space:
mode:
authorBen Fuhrmannek2021-02-16 11:16:59 +0100
committerBen Fuhrmannek2021-02-16 11:16:59 +0100
commit5484bcb5eb2714e7438927e2566c86a74d7c51af (patch)
treeb78326d2999397be4c08e06b23209981f82a4ea9 /src/sp_disabled_functions.c
parent7ac1e3866ef4f146c6c93a5ca13b9aebb14e936a (diff)
parentcecfdd808da67be908dbe7144cc8c74dfb3f855e (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src/sp_disabled_functions.c')
-rw-r--r--src/sp_disabled_functions.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c
index 6cb5446..c47b5cb 100644
--- a/src/sp_disabled_functions.c
+++ b/src/sp_disabled_functions.c
@@ -40,7 +40,7 @@ static bool is_functions_list_matching(zend_execute_data* execute_data,
40 sp_list_node* functions_list) { 40 sp_list_node* functions_list) {
41 zend_execute_data *orig_execute_data, *current; 41 zend_execute_data *orig_execute_data, *current;
42 orig_execute_data = current = execute_data; 42 orig_execute_data = current = execute_data;
43 sp_list_node* it = functions_list; 43 sp_list_node const* it = functions_list;
44 44
45 while (current) { 45 while (current) {
46 if (it == NULL) { // every function in the list matched, we've got a match! 46 if (it == NULL) { // every function in the list matched, we've got a match!
@@ -50,7 +50,7 @@ static bool is_functions_list_matching(zend_execute_data* execute_data,
50 50
51 EG(current_execute_data) = current; 51 EG(current_execute_data) = current;
52 52
53 char* complete_path_function = get_complete_function_path(current); 53 char* const complete_path_function = get_complete_function_path(current);
54 if (!complete_path_function) { 54 if (!complete_path_function) {
55 break; 55 break;
56 } 56 }
@@ -59,10 +59,8 @@ static bool is_functions_list_matching(zend_execute_data* execute_data,
59 59
60 if (0 == match) { 60 if (0 == match) {
61 it = it->next; 61 it = it->next;
62 current = current->prev_execute_data;
63 } else {
64 break;
65 } 62 }
63 current = current->prev_execute_data;
66 } 64 }
67 65
68 EG(current_execute_data) = orig_execute_data; 66 EG(current_execute_data) = orig_execute_data;
@@ -87,7 +85,8 @@ static bool is_local_var_matching(
87 return true; 85 return true;
88 } 86 }
89 } else { 87 } else {
90 const zend_string* var_value_str = sp_zval_to_zend_string(var_value); 88 zend_string const* const var_value_str =
89 sp_zval_to_zend_string(var_value);
91 bool match = sp_match_value(var_value_str, config_node->value, 90 bool match = sp_match_value(var_value_str, config_node->value,
92 config_node->r_value); 91 config_node->r_value);
93 92
@@ -329,7 +328,7 @@ static void should_disable(zend_execute_data* execute_data,
329 } 328 }
330 329
331 if (config_node->cidr) { 330 if (config_node->cidr) {
332 char* client_ip = getenv("REMOTE_ADDR"); 331 const char* client_ip = get_ipaddr();
333 if (client_ip && false == cidr_match(client_ip, config_node->cidr)) { 332 if (client_ip && false == cidr_match(client_ip, config_node->cidr)) {
334 goto next; 333 goto next;
335 } 334 }
@@ -361,7 +360,7 @@ static void should_disable(zend_execute_data* execute_data,
361#else 360#else
362 execute_data->func->op_array.arg_info->is_variadic 361 execute_data->func->op_array.arg_info->is_variadic
363#endif 362#endif
364 ){ 363 ) {
365 sp_log_warn( 364 sp_log_warn(
366 "disable_function", 365 "disable_function",
367 "Snuffleupagus doesn't support variadic functions yet, sorry. " 366 "Snuffleupagus doesn't support variadic functions yet, sorry. "
@@ -525,13 +524,13 @@ static int hook_functions_regexp(const sp_list_node* config) {
525 return SUCCESS; 524 return SUCCESS;
526} 525}
527 526
528static int hook_functions(HashTable* to_hook_ht, HashTable* hooked_ht) { 527static void hook_functions(HashTable* to_hook_ht, HashTable* hooked_ht) {
529 zend_string* key; 528 zend_string* key;
530 zval* value; 529 zval* value;
531 530
532 ZEND_HASH_FOREACH_STR_KEY_VAL(to_hook_ht, key, value) { 531 ZEND_HASH_FOREACH_STR_KEY_VAL(to_hook_ht, key, value) {
533 bool hooked = !HOOK_FUNCTION(ZSTR_VAL(key), disabled_functions_hook, 532 bool hooked = HOOK_FUNCTION(ZSTR_VAL(key), disabled_functions_hook,
534 PHP_FN(check_disabled_function)); 533 PHP_FN(check_disabled_function));
535 bool is_builtin = 534 bool is_builtin =
536 check_is_builtin_name(((sp_list_node*)Z_PTR_P(value))->data); 535 check_is_builtin_name(((sp_list_node*)Z_PTR_P(value))->data);
537 if (hooked || is_builtin) { 536 if (hooked || is_builtin) {
@@ -540,7 +539,6 @@ static int hook_functions(HashTable* to_hook_ht, HashTable* hooked_ht) {
540 } 539 }
541 } 540 }
542 ZEND_HASH_FOREACH_END(); 541 ZEND_HASH_FOREACH_END();
543 return SUCCESS;
544} 542}
545 543
546ZEND_FUNCTION(eval_blacklist_callback) { 544ZEND_FUNCTION(eval_blacklist_callback) {
@@ -565,13 +563,13 @@ ZEND_FUNCTION(eval_blacklist_callback) {
565 SP_TOKEN_EVAL_BLACKLIST); 563 SP_TOKEN_EVAL_BLACKLIST);
566 } 564 }
567 if (config_eval->simulation) { 565 if (config_eval->simulation) {
568 sp_log_msg("eval", SP_LOG_SIMULATION, 566 sp_log_simulation("eval",
569 "A call to %s was tried in eval, in %s:%d, logging it.", 567 "A call to %s was tried in eval, in %s:%d, logging it.",
570 current_function_name, ZSTR_VAL(filename), line_number); 568 current_function_name, ZSTR_VAL(filename), line_number);
571 } else { 569 } else {
572 sp_log_msg("eval", SP_LOG_DROP, 570 sp_log_drop("eval",
573 "A call to %s was tried in eval, in %s:%d, dropping it.", 571 "A call to %s was tried in eval, in %s:%d, dropping it.",
574 current_function_name, ZSTR_VAL(filename), line_number); 572 current_function_name, ZSTR_VAL(filename), line_number);
575 } 573 }
576 efree(filename); 574 efree(filename);
577 } 575 }
@@ -588,13 +586,11 @@ int hook_disabled_functions(void) {
588 586
589 int ret = SUCCESS; 587 int ret = SUCCESS;
590 588
591 ret |= 589 hook_functions(SNUFFLEUPAGUS_G(config).config_disabled_functions,
592 hook_functions(SNUFFLEUPAGUS_G(config).config_disabled_functions, 590 SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked);
593 SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked);
594 591
595 ret |= hook_functions( 592 hook_functions(SNUFFLEUPAGUS_G(config).config_disabled_functions_ret,
596 SNUFFLEUPAGUS_G(config).config_disabled_functions_ret, 593 SNUFFLEUPAGUS_G(config).config_disabled_functions_ret_hooked);
597 SNUFFLEUPAGUS_G(config).config_disabled_functions_ret_hooked);
598 594
599 ret |= hook_functions_regexp( 595 ret |= hook_functions_regexp(
600 SNUFFLEUPAGUS_G(config) 596 SNUFFLEUPAGUS_G(config)
@@ -619,7 +615,11 @@ int hook_disabled_functions(void) {
619 615
620zend_write_func_t zend_write_default = NULL; 616zend_write_func_t zend_write_default = NULL;
621 617
618#if PHP_VERSION_ID >= 80000
619size_t hook_echo(const char* str, size_t str_length) {
620#else
622int hook_echo(const char* str, size_t str_length) { 621int hook_echo(const char* str, size_t str_length) {
622#endif
623 zend_string* zs = zend_string_init(str, str_length, 0); 623 zend_string* zs = zend_string_init(str, str_length, 0);
624 624
625 should_disable_ht( 625 should_disable_ht(