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_unserialize.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/sp_unserialize.c') diff --git a/src/sp_unserialize.c b/src/sp_unserialize.c index 1b47416..fe738e6 100644 --- a/src/sp_unserialize.c +++ b/src/sp_unserialize.c @@ -6,9 +6,9 @@ PHP_FUNCTION(sp_serialize) { zif_handler orig_handler; /* Call the original `serialize` function. */ - orig_handler = zend_hash_str_find_ptr( - SNUFFLEUPAGUS_G(sp_internal_functions_hook), "serialize", - sizeof("serialize") - 1); + orig_handler = + zend_hash_str_find_ptr(SNUFFLEUPAGUS_G(sp_internal_functions_hook), + "serialize", sizeof("serialize") - 1); orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); /* Compute the HMAC of the textual representation of the serialized data*/ @@ -26,9 +26,11 @@ PHP_FUNCTION(sp_serialize) { size_t len = Z_STRLEN_P(return_value) + Z_STRLEN(hmac); if (len < Z_STRLEN_P(return_value)) { + // LCOV_EXCL_START sp_log_err("overflow_error", "Overflow tentative detected in sp_serialize."); zend_bailout(); + // LCOV_EXCL_STOP } zend_string *res = zend_string_alloc(len, 0); @@ -51,7 +53,7 @@ PHP_FUNCTION(sp_unserialize) { size_t buf_len = 0; zval *opts = NULL; - const sp_config_unserialize* config_unserialize = + const sp_config_unserialize *config_unserialize = SNUFFLEUPAGUS_G(config).config_unserialize; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|a", &buf, &buf_len, &opts) == @@ -63,7 +65,6 @@ PHP_FUNCTION(sp_unserialize) { if (buf_len < 64) { sp_log_msg("unserialize", SP_LOG_DROP, "The serialized object is too small."); - RETURN_FALSE; } hmac = buf + buf_len - 64; @@ -94,6 +95,11 @@ PHP_FUNCTION(sp_unserialize) { orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); } } else { + if (config_unserialize->dump) { + sp_log_request(config_unserialize->dump, + config_unserialize->textual_representation, + SP_TOKEN_UNSERIALIZE_HMAC); + } if (true == config_unserialize->simulation) { sp_log_msg("unserialize", SP_LOG_SIMULATION, "Invalid HMAC for %s", serialized_str); @@ -107,11 +113,6 @@ PHP_FUNCTION(sp_unserialize) { serialized_str); } } - if (config_unserialize->dump) { - sp_log_request(config_unserialize->dump, - config_unserialize->textual_representation, - SP_TOKEN_UNSERIALIZE_HMAC); - } efree(serialized_str); return; } -- cgit v1.3