summaryrefslogtreecommitdiff
path: root/src/sp_cookie_encryption.c
diff options
context:
space:
mode:
authorjvoisin2018-10-06 16:15:00 +0000
committerGitHub2018-10-06 16:15:00 +0000
commitaa550b9abadc109a2c89a7cd6dd047ac2a953027 (patch)
tree1892e9ce8f833f3f13278cd424368fe1b5e26d91 /src/sp_cookie_encryption.c
parent228fadf307b167a22ad6ec760f3b2ee2e9f2fee3 (diff)
Bump a bit the coverage
* `setcookie` doesn't always return `true` anymore * clang-format * Cookies with invalid decryption are dropped, but the request isn't anymore * faulty unserialize are now dumpable
Diffstat (limited to 'src/sp_cookie_encryption.c')
-rw-r--r--src/sp_cookie_encryption.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/sp_cookie_encryption.c b/src/sp_cookie_encryption.c
index 31dde95..4e5242d 100644
--- a/src/sp_cookie_encryption.c
+++ b/src/sp_cookie_encryption.c
@@ -43,11 +43,12 @@ static zend_string *encrypt_data(zend_string *data) {
43} 43}
44 44
45PHP_FUNCTION(sp_setcookie) { 45PHP_FUNCTION(sp_setcookie) {
46 zend_string *name = NULL, *value = NULL, *path = NULL, *domain = NULL, *value_enc = NULL, 46 zend_string *name = NULL, *value = NULL, *path = NULL, *domain = NULL,
47 *value_enc = NULL,
47#if PHP_VERSION_ID < 70300 48#if PHP_VERSION_ID < 70300
48 *path_samesite = NULL; 49 *path_samesite = NULL;
49#else 50#else
50 *samesite = NULL; 51 *samesite = NULL;
51#endif 52#endif
52 53
53 zend_long expires = 0; 54 zend_long expires = 0;
@@ -95,7 +96,6 @@ PHP_FUNCTION(sp_setcookie) {
95 value_enc = encrypt_data(value); 96 value_enc = encrypt_data(value);
96 } 97 }
97 98
98
99 if (cookie_node && cookie_node->samesite) { 99 if (cookie_node && cookie_node->samesite) {
100 if (!path) { 100 if (!path) {
101 path = zend_string_init("", 0, 0); 101 path = zend_string_init("", 0, 0);
@@ -112,19 +112,20 @@ PHP_FUNCTION(sp_setcookie) {
112 memcpy(ZSTR_VAL(path_samesite) + ZSTR_LEN(path), cookie_samesite, 112 memcpy(ZSTR_VAL(path_samesite) + ZSTR_LEN(path), cookie_samesite,
113 strlen(cookie_samesite) + 1); 113 strlen(cookie_samesite) + 1);
114#else 114#else
115 cookie_samesite = (cookie_node->samesite == lax) 115 cookie_samesite = (cookie_node->samesite == lax) ? SP_TOKEN_SAMESITE_LAX
116 ? SP_TOKEN_SAMESITE_LAX 116 : SP_TOKEN_SAMESITE_STRICT;
117 : SP_TOKEN_SAMESITE_STRICT;
118 117
119 samesite = zend_string_init(cookie_samesite, strlen(cookie_samesite), 0); 118 samesite = zend_string_init(cookie_samesite, strlen(cookie_samesite), 0);
120#endif 119#endif
121 } 120 }
122 121
123
124#if PHP_VERSION_ID < 70300 122#if PHP_VERSION_ID < 70300
125 if (php_setcookie(name, (value_enc ? value_enc : value), expires, (path_samesite ? path_samesite : path), domain, secure, 1, httponly)) { 123 if (php_setcookie(name, (value_enc ? value_enc : value), expires,
124 (path_samesite ? path_samesite : path), domain, secure, 1,
125 httponly) == SUCCESS) {
126#else 126#else
127 if (php_setcookie(name, (value_enc ? value_enc : value), expires, path, domain, secure, httponly, samesite, 1)) { 127 if (php_setcookie(name, (value_enc ? value_enc : value), expires, path,
128 domain, secure, httponly, samesite, 1) == SUCCESS) {
128#endif 129#endif
129 RETVAL_TRUE; 130 RETVAL_TRUE;
130 } else { 131 } else {
@@ -139,7 +140,6 @@ PHP_FUNCTION(sp_setcookie) {
139 zend_string_release(path_samesite); 140 zend_string_release(path_samesite);
140 } 141 }
141#endif 142#endif
142 RETURN_TRUE; // TODO why always true ?
143} 143}
144 144
145int hook_cookies() { 145int hook_cookies() {