diff options
| author | jvoisin | 2017-12-19 14:54:47 +0100 |
|---|---|---|
| committer | jvoisin | 2017-12-19 14:54:47 +0100 |
| commit | 451d23a2c67694d3ac7ecb602c34da23a227f1f9 (patch) | |
| tree | 9ebec3c91ef617db9f5035ee01f5242e1f28f869 /src/sp_cookie_encryption.c | |
| parent | 560b6fc407237aa240e7a76691f6ab46562b0fa0 (diff) | |
Rework a bit the order of operation
- There is no need to generate the key if the cookie has no value
- There is no need to generate the key if the cookie length is invalid
- Use yoda condition
Diffstat (limited to 'src/sp_cookie_encryption.c')
| -rw-r--r-- | src/sp_cookie_encryption.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/sp_cookie_encryption.c b/src/sp_cookie_encryption.c index 9e585c5..2bb305f 100644 --- a/src/sp_cookie_encryption.c +++ b/src/sp_cookie_encryption.c | |||
| @@ -53,13 +53,13 @@ int decrypt_cookie(zval *pDest, int num_args, va_list args, | |||
| 53 | return ZEND_HASH_APPLY_KEEP; | 53 | return ZEND_HASH_APPLY_KEEP; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | generate_key(key); | 56 | /* If the cookie has no value, it shouldn't be encrypted. */ |
| 57 | 57 | if (0 == Z_STRLEN_P(pDest)) { | |
| 58 | if (Z_STRLEN_P(pDest) == 0) { | ||
| 59 | return ZEND_HASH_APPLY_KEEP; | 58 | return ZEND_HASH_APPLY_KEEP; |
| 60 | } | 59 | } |
| 61 | 60 | ||
| 62 | debase64 = php_base64_decode((unsigned char *)(Z_STRVAL_P(pDest)), Z_STRLEN_P(pDest)); | 61 | debase64 = php_base64_decode((unsigned char *)(Z_STRVAL_P(pDest)), |
| 62 | Z_STRLEN_P(pDest)); | ||
| 63 | 63 | ||
| 64 | if (ZSTR_LEN(debase64) < | 64 | if (ZSTR_LEN(debase64) < |
| 65 | crypto_secretbox_NONCEBYTES + crypto_secretbox_ZEROBYTES) { | 65 | crypto_secretbox_NONCEBYTES + crypto_secretbox_ZEROBYTES) { |
| @@ -68,6 +68,8 @@ int decrypt_cookie(zval *pDest, int num_args, va_list args, | |||
| 68 | return ZEND_HASH_APPLY_REMOVE; | 68 | return ZEND_HASH_APPLY_REMOVE; |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | generate_key(key); | ||
| 72 | |||
| 71 | decrypted = pecalloc(ZSTR_LEN(debase64), 1, 0); | 73 | decrypted = pecalloc(ZSTR_LEN(debase64), 1, 0); |
| 72 | 74 | ||
| 73 | ret = crypto_secretbox_open( | 75 | ret = crypto_secretbox_open( |
