From aa550b9abadc109a2c89a7cd6dd047ac2a953027 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 6 Oct 2018 16:15:00 +0000 Subject: 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--- src/sp_cookie_encryption.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/sp_cookie_encryption.c') 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) { } PHP_FUNCTION(sp_setcookie) { - zend_string *name = NULL, *value = NULL, *path = NULL, *domain = NULL, *value_enc = NULL, + zend_string *name = NULL, *value = NULL, *path = NULL, *domain = NULL, + *value_enc = NULL, #if PHP_VERSION_ID < 70300 - *path_samesite = NULL; + *path_samesite = NULL; #else - *samesite = NULL; + *samesite = NULL; #endif zend_long expires = 0; @@ -95,7 +96,6 @@ PHP_FUNCTION(sp_setcookie) { value_enc = encrypt_data(value); } - if (cookie_node && cookie_node->samesite) { if (!path) { path = zend_string_init("", 0, 0); @@ -112,19 +112,20 @@ PHP_FUNCTION(sp_setcookie) { memcpy(ZSTR_VAL(path_samesite) + ZSTR_LEN(path), cookie_samesite, strlen(cookie_samesite) + 1); #else - cookie_samesite = (cookie_node->samesite == lax) - ? SP_TOKEN_SAMESITE_LAX - : SP_TOKEN_SAMESITE_STRICT; + cookie_samesite = (cookie_node->samesite == lax) ? SP_TOKEN_SAMESITE_LAX + : SP_TOKEN_SAMESITE_STRICT; samesite = zend_string_init(cookie_samesite, strlen(cookie_samesite), 0); #endif } - #if PHP_VERSION_ID < 70300 - if (php_setcookie(name, (value_enc ? value_enc : value), expires, (path_samesite ? path_samesite : path), domain, secure, 1, httponly)) { + if (php_setcookie(name, (value_enc ? value_enc : value), expires, + (path_samesite ? path_samesite : path), domain, secure, 1, + httponly) == SUCCESS) { #else - if (php_setcookie(name, (value_enc ? value_enc : value), expires, path, domain, secure, httponly, samesite, 1)) { + if (php_setcookie(name, (value_enc ? value_enc : value), expires, path, + domain, secure, httponly, samesite, 1) == SUCCESS) { #endif RETVAL_TRUE; } else { @@ -139,7 +140,6 @@ PHP_FUNCTION(sp_setcookie) { zend_string_release(path_samesite); } #endif - RETURN_TRUE; // TODO why always true ? } int hook_cookies() { -- cgit v1.3