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_harden_rand.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_harden_rand.c')
| -rw-r--r-- | src/sp_harden_rand.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/src/sp_harden_rand.c b/src/sp_harden_rand.c index 43c2a5b..3e9bcb3 100644 --- a/src/sp_harden_rand.c +++ b/src/sp_harden_rand.c | |||
| @@ -54,8 +54,7 @@ PHP_FUNCTION(sp_rand) { | |||
| 54 | 54 | ||
| 55 | /* call the original `rand` function, | 55 | /* call the original `rand` function, |
| 56 | * since we might no be the only ones to hook it*/ | 56 | * since we might no be the only ones to hook it*/ |
| 57 | orig_handler = zend_hash_str_find_ptr( | 57 | orig_handler = zend_hash_str_find_ptr(SPG(sp_internal_functions_hook), ZEND_STRL("rand")); |
| 58 | SNUFFLEUPAGUS_G(sp_internal_functions_hook), "rand", sizeof("rand") - 1); | ||
| 59 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 58 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 60 | 59 | ||
| 61 | random_int_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 60 | random_int_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| @@ -67,8 +66,7 @@ PHP_FUNCTION(sp_mt_rand) { | |||
| 67 | /* call the original `mt_rand` function, | 66 | /* call the original `mt_rand` function, |
| 68 | * since we might no be the only ones to hook it*/ | 67 | * since we might no be the only ones to hook it*/ |
| 69 | orig_handler = | 68 | orig_handler = |
| 70 | zend_hash_str_find_ptr(SNUFFLEUPAGUS_G(sp_internal_functions_hook), | 69 | zend_hash_str_find_ptr(SPG(sp_internal_functions_hook), ZEND_STRL("mt_rand")); |
| 71 | "mt_rand", sizeof("mt_rand") - 1); | ||
| 72 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 70 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 73 | 71 | ||
| 74 | random_int_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 72 | random_int_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
