diff options
| author | Ben Fuhrmannek | 2021-09-23 12:23:40 +0200 |
|---|---|---|
| committer | Ben Fuhrmannek | 2021-09-23 12:23:40 +0200 |
| commit | 54c352c1b5aa08b187dd1e52e544709cad2b0fee (patch) | |
| tree | d15bf0f484c6baa1f2718e625e0d49f6fb488507 /src/sp_disabled_functions.c | |
| parent | 887e1c9d44fbcf5f23a928269034593b8521aaba (diff) | |
config is stack allocated now + some code improvements (see details)
* for easier memory manegement, the entire sp_config struct was merged into snuffleupagus_globals and allocated on stack where possible
* SNUFFLEUPAGUS_G() can be written as SPG(), which is faster to type and easier to read
* execution_depth is re-initialized to 0 for each request
* function calls with inline string and length parameters consistently use ZEND_STRL instead of sizeof()-1
* execution is actually hooked if recursion protection is enabled
* some line breaks were removed to make the code more readable
Diffstat (limited to 'src/sp_disabled_functions.c')
| -rw-r--r-- | src/sp_disabled_functions.c | 46 |
1 files changed, 14 insertions, 32 deletions
diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c index 6ff3915..4ef72bf 100644 --- a/src/sp_disabled_functions.c +++ b/src/sp_disabled_functions.c | |||
| @@ -479,21 +479,13 @@ ZEND_FUNCTION(check_disabled_function) { | |||
| 479 | zif_handler orig_handler; | 479 | zif_handler orig_handler; |
| 480 | const char* current_function_name = get_active_function_name(TSRMLS_C); | 480 | const char* current_function_name = get_active_function_name(TSRMLS_C); |
| 481 | 481 | ||
| 482 | should_disable_ht( | 482 | should_disable_ht(execute_data, current_function_name, NULL, NULL, SPCFG(disabled_functions_reg).disabled_functions, SPCFG(disabled_functions_hooked)); |
| 483 | execute_data, current_function_name, NULL, NULL, | ||
| 484 | SNUFFLEUPAGUS_G(config).config_disabled_functions_reg->disabled_functions, | ||
| 485 | SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked); | ||
| 486 | 483 | ||
| 487 | orig_handler = zend_hash_str_find_ptr( | 484 | orig_handler = zend_hash_str_find_ptr( |
| 488 | SNUFFLEUPAGUS_G(disabled_functions_hook), current_function_name, | 485 | SPG(disabled_functions_hook), current_function_name, |
| 489 | strlen(current_function_name)); | 486 | strlen(current_function_name)); |
| 490 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 487 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 491 | should_drop_on_ret_ht( | 488 | should_drop_on_ret_ht(return_value, current_function_name, SPCFG(disabled_functions_reg_ret).disabled_functions, SPCFG(disabled_functions_ret_hooked), execute_data); |
| 492 | return_value, current_function_name, | ||
| 493 | SNUFFLEUPAGUS_G(config) | ||
| 494 | .config_disabled_functions_reg_ret->disabled_functions, | ||
| 495 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret_hooked, | ||
| 496 | execute_data); | ||
| 497 | } | 489 | } |
| 498 | 490 | ||
| 499 | static int hook_functions_regexp(const sp_list_node* config) { | 491 | static int hook_functions_regexp(const sp_list_node* config) { |
| @@ -547,10 +539,10 @@ ZEND_FUNCTION(eval_blacklist_callback) { | |||
| 547 | } | 539 | } |
| 548 | zend_string_release(tmp); | 540 | zend_string_release(tmp); |
| 549 | 541 | ||
| 550 | if (SNUFFLEUPAGUS_G(in_eval) > 0) { | 542 | if (SPG(in_eval) > 0) { |
| 551 | // zend_string* filename = get_eval_filename(zend_get_executed_filename()); | 543 | // zend_string* filename = get_eval_filename(zend_get_executed_filename()); |
| 552 | // const int line_number = zend_get_executed_lineno(TSRMLS_C); | 544 | // const int line_number = zend_get_executed_lineno(TSRMLS_C); |
| 553 | const sp_config_eval* config_eval = SNUFFLEUPAGUS_G(config).config_eval; | 545 | const sp_config_eval* config_eval = &(SPCFG(eval)); |
| 554 | 546 | ||
| 555 | if (config_eval->dump) { | 547 | if (config_eval->dump) { |
| 556 | sp_log_request(config_eval->dump, config_eval->textual_representation); | 548 | sp_log_request(config_eval->dump, config_eval->textual_representation); |
| @@ -565,7 +557,7 @@ ZEND_FUNCTION(eval_blacklist_callback) { | |||
| 565 | 557 | ||
| 566 | whitelisted: | 558 | whitelisted: |
| 567 | orig_handler = zend_hash_str_find_ptr( | 559 | orig_handler = zend_hash_str_find_ptr( |
| 568 | SNUFFLEUPAGUS_G(sp_eval_blacklist_functions_hook), current_function_name, | 560 | SPG(sp_eval_blacklist_functions_hook), current_function_name, |
| 569 | strlen(current_function_name)); | 561 | strlen(current_function_name)); |
| 570 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 562 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 571 | } | 563 | } |
| @@ -575,26 +567,19 @@ int hook_disabled_functions(void) { | |||
| 575 | 567 | ||
| 576 | int ret = SUCCESS; | 568 | int ret = SUCCESS; |
| 577 | 569 | ||
| 578 | hook_functions(SNUFFLEUPAGUS_G(config).config_disabled_functions, | 570 | hook_functions(SPCFG(disabled_functions), SPCFG(disabled_functions_hooked)); |
| 579 | SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked); | 571 | hook_functions(SPCFG(disabled_functions_ret), SPCFG(disabled_functions_ret_hooked)); |
| 580 | 572 | ||
| 581 | hook_functions(SNUFFLEUPAGUS_G(config).config_disabled_functions_ret, | 573 | ret |= hook_functions_regexp(SPCFG(disabled_functions_reg).disabled_functions); |
| 582 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret_hooked); | ||
| 583 | 574 | ||
| 584 | ret |= hook_functions_regexp( | 575 | ret |= hook_functions_regexp(SPCFG(disabled_functions_reg_ret).disabled_functions); |
| 585 | SNUFFLEUPAGUS_G(config) | ||
| 586 | .config_disabled_functions_reg->disabled_functions); | ||
| 587 | 576 | ||
| 588 | ret |= hook_functions_regexp( | 577 | if (NULL != SPCFG(eval).blacklist) { |
| 589 | SNUFFLEUPAGUS_G(config) | 578 | sp_list_node* it = SPCFG(eval).blacklist; |
| 590 | .config_disabled_functions_reg_ret->disabled_functions); | ||
| 591 | |||
| 592 | if (NULL != SNUFFLEUPAGUS_G(config).config_eval->blacklist) { | ||
| 593 | sp_list_node* it = SNUFFLEUPAGUS_G(config).config_eval->blacklist; | ||
| 594 | 579 | ||
| 595 | while (it) { | 580 | while (it) { |
| 596 | hook_function(ZSTR_VAL((zend_string*)it->data), | 581 | hook_function(ZSTR_VAL((zend_string*)it->data), |
| 597 | SNUFFLEUPAGUS_G(sp_eval_blacklist_functions_hook), | 582 | SPG(sp_eval_blacklist_functions_hook), |
| 598 | PHP_FN(eval_blacklist_callback)); | 583 | PHP_FN(eval_blacklist_callback)); |
| 599 | it = it->next; | 584 | it = it->next; |
| 600 | } | 585 | } |
| @@ -611,10 +596,7 @@ int hook_echo(const char* str, size_t str_length) { | |||
| 611 | #endif | 596 | #endif |
| 612 | zend_string* zs = zend_string_init(str, str_length, 0); | 597 | zend_string* zs = zend_string_init(str, str_length, 0); |
| 613 | 598 | ||
| 614 | should_disable_ht( | 599 | should_disable_ht(EG(current_execute_data), "echo", zs, NULL, SPCFG(disabled_functions_reg).disabled_functions, SPCFG(disabled_functions_hooked)); |
| 615 | EG(current_execute_data), "echo", zs, NULL, | ||
| 616 | SNUFFLEUPAGUS_G(config).config_disabled_functions_reg->disabled_functions, | ||
| 617 | SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked); | ||
| 618 | 600 | ||
| 619 | zend_string_release(zs); | 601 | zend_string_release(zs); |
| 620 | 602 | ||
