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_crypt.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_crypt.c')
| -rw-r--r-- | src/sp_crypt.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/sp_crypt.c b/src/sp_crypt.c index ff8f65e..c1d9403 100644 --- a/src/sp_crypt.c +++ b/src/sp_crypt.c | |||
| @@ -3,13 +3,10 @@ | |||
| 3 | void generate_key(unsigned char *key) { | 3 | void generate_key(unsigned char *key) { |
| 4 | PHP_SHA256_CTX ctx; | 4 | PHP_SHA256_CTX ctx; |
| 5 | const char *user_agent = getenv("HTTP_USER_AGENT"); | 5 | const char *user_agent = getenv("HTTP_USER_AGENT"); |
| 6 | const zend_string *env_var_zend = | 6 | const zend_string *env_var_zend = SPCFG(cookies_env_var); |
| 7 | SNUFFLEUPAGUS_G(config).config_snuffleupagus->cookies_env_var; | 7 | const zend_string *encryption_key_zend = SPCFG(encryption_key); |
| 8 | const zend_string *encryption_key_zend = | ||
| 9 | SNUFFLEUPAGUS_G(config).config_snuffleupagus->encryption_key; | ||
| 10 | const char *env_var = (env_var_zend ? getenv(ZSTR_VAL(env_var_zend)) : NULL); | 8 | const char *env_var = (env_var_zend ? getenv(ZSTR_VAL(env_var_zend)) : NULL); |
| 11 | const char *encryption_key = | 9 | const char *encryption_key = (encryption_key_zend ? ZSTR_VAL(encryption_key_zend) : NULL); |
| 12 | (encryption_key_zend ? ZSTR_VAL(encryption_key_zend) : NULL); | ||
| 13 | 10 | ||
| 14 | assert(32 == crypto_secretbox_KEYBYTES); // 32 is the size of a SHA256. | 11 | assert(32 == crypto_secretbox_KEYBYTES); // 32 is the size of a SHA256. |
| 15 | assert(encryption_key); // Encryption key can't be NULL | 12 | assert(encryption_key); // Encryption key can't be NULL |
