diff options
Diffstat (limited to 'src/sp_session.c')
| -rw-r--r-- | src/sp_session.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/sp_session.c b/src/sp_session.c index 7fa4937..64233d1 100644 --- a/src/sp_session.c +++ b/src/sp_session.c | |||
| @@ -24,21 +24,35 @@ static int (*old_s_write)(PS_WRITE_ARGS); | |||
| 24 | static int (*previous_sessionRINIT)(INIT_FUNC_ARGS) = NULL; | 24 | static int (*previous_sessionRINIT)(INIT_FUNC_ARGS) = NULL; |
| 25 | static ZEND_INI_MH((*old_OnUpdateSaveHandler)) = NULL; | 25 | static ZEND_INI_MH((*old_OnUpdateSaveHandler)) = NULL; |
| 26 | 26 | ||
| 27 | static void check_sid_length(zend_string *sid) { | ||
| 28 | const sp_config_session *cfg = SNUFFLEUPAGUS_G(config).config_session; | ||
| 29 | |||
| 30 | if (sid) { | ||
| 31 | if (cfg->sid_min_length && ZSTR_LEN(sid) < cfg->sid_min_length) { | ||
| 32 | sp_log_auto("session", cfg->simulation, "Session ID is too short"); | ||
| 33 | } | ||
| 34 | if (cfg->sid_max_length && ZSTR_LEN(sid) > cfg->sid_max_length) { | ||
| 35 | sp_log_auto("session", cfg->simulation, "Session ID is too long"); | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 27 | static int sp_hook_s_read(PS_READ_ARGS) { | 40 | static int sp_hook_s_read(PS_READ_ARGS) { |
| 41 | const sp_config_session *cfg = SNUFFLEUPAGUS_G(config).config_session; | ||
| 42 | check_sid_length(key); | ||
| 43 | |||
| 28 | int r = old_s_read(mod_data, key, val, maxlifetime); | 44 | int r = old_s_read(mod_data, key, val, maxlifetime); |
| 29 | const sp_config_session *config_session = | ||
| 30 | SNUFFLEUPAGUS_G(config).config_session; | ||
| 31 | 45 | ||
| 32 | if ((NULL == val) || (NULL == *val) || (0 == ZSTR_LEN(*val))) { | 46 | if ((NULL == val) || (NULL == *val) || (0 == ZSTR_LEN(*val))) { |
| 33 | return r; | 47 | return r; |
| 34 | } | 48 | } |
| 35 | 49 | ||
| 36 | if (r == SUCCESS && config_session->encrypt) { | 50 | if (r == SUCCESS && cfg->encrypt) { |
| 37 | zend_string *orig_val = *val; | 51 | zend_string *orig_val = *val; |
| 38 | zval val_zval; | 52 | zval val_zval; |
| 39 | ZVAL_PSTRINGL(&val_zval, ZSTR_VAL(*val), ZSTR_LEN(*val)); | 53 | ZVAL_PSTRINGL(&val_zval, ZSTR_VAL(*val), ZSTR_LEN(*val)); |
| 40 | 54 | ||
| 41 | int ret = decrypt_zval(&val_zval, config_session->simulation, NULL); | 55 | int ret = decrypt_zval(&val_zval, cfg->simulation, NULL); |
| 42 | if (ZEND_HASH_APPLY_KEEP != ret) { | 56 | if (ZEND_HASH_APPLY_KEEP != ret) { |
| 43 | zend_bailout(); | 57 | zend_bailout(); |
| 44 | } | 58 | } |
| @@ -51,7 +65,10 @@ static int sp_hook_s_read(PS_READ_ARGS) { | |||
| 51 | } | 65 | } |
| 52 | 66 | ||
| 53 | static int sp_hook_s_write(PS_WRITE_ARGS) { | 67 | static int sp_hook_s_write(PS_WRITE_ARGS) { |
| 54 | if (ZSTR_LEN(val) > 0 && SNUFFLEUPAGUS_G(config).config_session->encrypt) { | 68 | const sp_config_session *cfg = SNUFFLEUPAGUS_G(config).config_session; |
| 69 | check_sid_length(key); | ||
| 70 | |||
| 71 | if (ZSTR_LEN(val) > 0 && cfg->encrypt) { | ||
| 55 | zend_string *new_val = encrypt_zval(val); | 72 | zend_string *new_val = encrypt_zval(val); |
| 56 | return old_s_write(mod_data, key, new_val, maxlifetime); | 73 | return old_s_write(mod_data, key, new_val, maxlifetime); |
| 57 | } | 74 | } |
