summaryrefslogtreecommitdiff
path: root/src/sp_wrapper.c
diff options
context:
space:
mode:
authorBen Fuhrmannek2021-09-23 12:23:40 +0200
committerBen Fuhrmannek2021-09-23 12:23:40 +0200
commit54c352c1b5aa08b187dd1e52e544709cad2b0fee (patch)
treed15bf0f484c6baa1f2718e625e0d49f6fb488507 /src/sp_wrapper.c
parent887e1c9d44fbcf5f23a928269034593b8521aaba (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_wrapper.c')
-rw-r--r--src/sp_wrapper.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/sp_wrapper.c b/src/sp_wrapper.c
index 7610114..1538e33 100644
--- a/src/sp_wrapper.c
+++ b/src/sp_wrapper.c
@@ -1,7 +1,7 @@
1#include "php_snuffleupagus.h" 1#include "php_snuffleupagus.h"
2 2
3static bool wrapper_is_whitelisted(const zend_string *const zs) { 3static bool wrapper_is_whitelisted(const zend_string *const zs) {
4 const sp_list_node *list = SNUFFLEUPAGUS_G(config).config_wrapper->whitelist; 4 const sp_list_node *list = SPCFG(wrapper).whitelist;
5 5
6 if (!zs) { 6 if (!zs) {
7 return false; // LCOV_EXCL_LINE 7 return false; // LCOV_EXCL_LINE
@@ -38,8 +38,7 @@ void sp_disable_wrapper() {
38 38
39 zend_hash_destroy(orig_complete); 39 zend_hash_destroy(orig_complete);
40 pefree(orig_complete, 1); 40 pefree(orig_complete, 1);
41 SNUFFLEUPAGUS_G(config).config_wrapper->num_wrapper = 41 SPCFG(wrapper).num_wrapper = zend_hash_num_elements(orig);
42 zend_hash_num_elements(orig);
43} 42}
44 43
45PHP_FUNCTION(sp_stream_wrapper_register) { 44PHP_FUNCTION(sp_stream_wrapper_register) {
@@ -53,9 +52,7 @@ PHP_FUNCTION(sp_stream_wrapper_register) {
53 // LCOV_EXCL_BR_END 52 // LCOV_EXCL_BR_END
54 53
55 if (wrapper_is_whitelisted(protocol_name)) { 54 if (wrapper_is_whitelisted(protocol_name)) {
56 orig_handler = zend_hash_str_find_ptr( 55 orig_handler = zend_hash_str_find_ptr(SPG(sp_internal_functions_hook), ZEND_STRL("stream_wrapper_register"));
57 SNUFFLEUPAGUS_G(sp_internal_functions_hook), "stream_wrapper_register",
58 sizeof("stream_wrapper_register") - 1);
59 orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); 56 orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
60 } 57 }
61} 58}