summaryrefslogtreecommitdiff
path: root/src/sp_utils.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_utils.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_utils.c')
-rw-r--r--src/sp_utils.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/sp_utils.c b/src/sp_utils.c
index 3e542f7..6634a8e 100644
--- a/src/sp_utils.c
+++ b/src/sp_utils.c
@@ -9,8 +9,7 @@
9 9
10ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus) 10ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus)
11 11
12bool sp_zend_string_equals(const zend_string* s1, 12bool sp_zend_string_equals(const zend_string* s1, const zend_string* s2) {
13 const zend_string* s2) {
14 // We can't use `zend_string_equals` here because it doesn't work on 13 // We can't use `zend_string_equals` here because it doesn't work on
15 // `const` zend_string. 14 // `const` zend_string.
16 return ZSTR_LEN(s1) == ZSTR_LEN(s2) && 15 return ZSTR_LEN(s1) == ZSTR_LEN(s2) &&
@@ -37,9 +36,11 @@ int compute_hash(const char* const filename, char* file_hash) {
37 php_stream* stream = 36 php_stream* stream =
38 php_stream_open_wrapper(filename, "rb", REPORT_ERRORS, NULL); 37 php_stream_open_wrapper(filename, "rb", REPORT_ERRORS, NULL);
39 if (!stream) { 38 if (!stream) {
39 // LCOV_EXCL_START
40 sp_log_err("hash_computation", 40 sp_log_err("hash_computation",
41 "Can not open the file %s to compute its hash", filename); 41 "Can not open the file %s to compute its hash", filename);
42 return FAILURE; 42 return FAILURE;
43 // LCOV_EXCL_STOP
43 } 44 }
44 45
45 PHP_SHA256Init(&context); 46 PHP_SHA256Init(&context);
@@ -133,9 +134,11 @@ static char* zend_string_to_char(const zend_string* zs) {
133 // Remove all \0 in a zend_string and replace them with '0' instead. 134 // Remove all \0 in a zend_string and replace them with '0' instead.
134 135
135 if (ZSTR_LEN(zs) + 1 < ZSTR_LEN(zs)) { 136 if (ZSTR_LEN(zs) + 1 < ZSTR_LEN(zs)) {
137 // LCOV_EXCL_START
136 sp_log_err("overflow_error", 138 sp_log_err("overflow_error",
137 "Overflow tentative detected in zend_string_to_char"); 139 "Overflow tentative detected in zend_string_to_char");
138 zend_bailout(); 140 zend_bailout();
141 // LCOV_EXCL_STOP
139 } 142 }
140 143
141 char* copy = ecalloc(ZSTR_LEN(zs) + 1, 1); 144 char* copy = ecalloc(ZSTR_LEN(zs) + 1, 1);
@@ -180,8 +183,9 @@ const zend_string* sp_zval_to_zend_string(const zval* zv) {
180 return zend_string_init("ARRAY", sizeof("ARRAY") - 1, 0); 183 return zend_string_init("ARRAY", sizeof("ARRAY") - 1, 0);
181 case IS_RESOURCE: 184 case IS_RESOURCE:
182 return zend_string_init("RESOURCE", sizeof("RESOURCE") - 1, 0); 185 return zend_string_init("RESOURCE", sizeof("RESOURCE") - 1, 0);
186 default:
187 return zend_string_init("", 0, 0); // LCOV_EXCL_LINE
183 } 188 }
184 return zend_string_init("", 0, 0);
185} 189}
186 190
187bool sp_match_value(const zend_string* value, const zend_string* to_match, 191bool sp_match_value(const zend_string* value, const zend_string* to_match,
@@ -216,12 +220,10 @@ void sp_log_disable(const char* restrict path, const char* restrict arg_name,
216 char_repr = zend_string_to_char(arg_value); 220 char_repr = zend_string_to_char(arg_value);
217 } 221 }
218 if (alias) { 222 if (alias) {
219 sp_log_msg( 223 sp_log_msg("disabled_function", sim ? SP_LOG_SIMULATION : SP_LOG_DROP,
220 "disabled_function", sim ? SP_LOG_SIMULATION : SP_LOG_DROP, 224 "Aborted execution on call of the function '%s', "
221 "Aborted execution on call of the function '%s', " 225 "because its argument '%s' content (%s) matched the rule '%s'",
222 "because its argument '%s' content (%s) matched the rule '%s'", 226 path, arg_name, char_repr ? char_repr : "?", ZSTR_VAL(alias));
223 path, arg_name, char_repr ? char_repr : "?",
224 ZSTR_VAL(alias));
225 } else { 227 } else {
226 sp_log_msg("disabled_function", sim ? SP_LOG_SIMULATION : SP_LOG_DROP, 228 sp_log_msg("disabled_function", sim ? SP_LOG_SIMULATION : SP_LOG_DROP,
227 "Aborted execution on call of the function '%s', " 229 "Aborted execution on call of the function '%s', "
@@ -237,8 +239,7 @@ void sp_log_disable(const char* restrict path, const char* restrict arg_name,
237 path, ZSTR_VAL(alias)); 239 path, ZSTR_VAL(alias));
238 } else { 240 } else {
239 sp_log_msg("disabled_function", sim ? SP_LOG_SIMULATION : SP_LOG_DROP, 241 sp_log_msg("disabled_function", sim ? SP_LOG_SIMULATION : SP_LOG_DROP,
240 "Aborted execution on call of the function '%s'", 242 "Aborted execution on call of the function '%s'", path);
241 path);
242 } 243 }
243 } 244 }
244} 245}
@@ -263,8 +264,7 @@ void sp_log_disable_ret(const char* restrict path,
263 "disabled_function", sim ? SP_LOG_SIMULATION : SP_LOG_DROP, 264 "disabled_function", sim ? SP_LOG_SIMULATION : SP_LOG_DROP,
264 "Aborted execution on return of the function '%s', " 265 "Aborted execution on return of the function '%s', "
265 "because the function returned '%s', which matched the rule '%s'", 266 "because the function returned '%s', which matched the rule '%s'",
266 path, char_repr ? char_repr : "?", 267 path, char_repr ? char_repr : "?", ZSTR_VAL(alias));
267 ZSTR_VAL(alias));
268 } else { 268 } else {
269 sp_log_msg("disabled_function", sim ? SP_LOG_SIMULATION : SP_LOG_DROP, 269 sp_log_msg("disabled_function", sim ? SP_LOG_SIMULATION : SP_LOG_DROP,
270 "Aborted execution on return of the function '%s', " 270 "Aborted execution on return of the function '%s', "
@@ -331,9 +331,11 @@ int hook_function(const char* original_name, HashTable* hook_table,
331 if (func->handler != new_function) { 331 if (func->handler != new_function) {
332 if (zend_hash_str_add_new_ptr((hook_table), VAR_AND_LEN(original_name), 332 if (zend_hash_str_add_new_ptr((hook_table), VAR_AND_LEN(original_name),
333 func->handler) == NULL) { 333 func->handler) == NULL) {
334 // LCOV_EXCL_START
334 sp_log_err("function_pointer_saving", 335 sp_log_err("function_pointer_saving",
335 "Could not save function pointer for %s", original_name); 336 "Could not save function pointer for %s", original_name);
336 return FAILURE; 337 return FAILURE;
338 // LCOV_EXCL_STOP
337 } 339 }
338 func->handler = new_function; 340 func->handler = new_function;
339 ret = SUCCESS; 341 ret = SUCCESS;