summaryrefslogtreecommitdiff
path: root/src/sp_disabled_functions.c
diff options
context:
space:
mode:
authorjvoisin2018-10-09 12:14:35 +0000
committerGitHub2018-10-09 12:14:35 +0000
commitb90387080a81952b330af225d4dc2bcbde14892d (patch)
tree07cc273059b2d1cffb861b1a48debdcd6c8cc9f3 /src/sp_disabled_functions.c
parent40cfba9328b9b27cfd2d2b66665780d9898cca2c (diff)
Don't check the return values of functions that might not return (#255)
This is due to our modifications to the logging system
Diffstat (limited to 'src/sp_disabled_functions.c')
-rw-r--r--src/sp_disabled_functions.c100
1 files changed, 47 insertions, 53 deletions
diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c
index b5cbe14..c483612 100644
--- a/src/sp_disabled_functions.c
+++ b/src/sp_disabled_functions.c
@@ -5,6 +5,18 @@
5 5
6ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus) 6ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus)
7 7
8static void should_disable(zend_execute_data* execute_data,
9 const char* complete_function_path,
10 const zend_string* builtin_param,
11 const char* builtin_param_name,
12 const sp_list_node* config,
13 const zend_string* current_filename);
14
15static void should_drop_on_ret(const zval* return_value,
16 const sp_list_node* config,
17 const char* complete_function_path,
18 zend_execute_data* execute_data);
19
8char* get_complete_function_path(zend_execute_data const* const execute_data) { 20char* get_complete_function_path(zend_execute_data const* const execute_data) {
9 if (zend_is_executing() && !EG(current_execute_data)->func) { 21 if (zend_is_executing() && !EG(current_execute_data)->func) {
10 return NULL; // LCOV_EXCL_LINE 22 return NULL; // LCOV_EXCL_LINE
@@ -249,17 +261,16 @@ static bool check_is_builtin_name(
249 return false; 261 return false;
250} 262}
251 263
252bool should_disable_ht(zend_execute_data* execute_data, 264void should_disable_ht(zend_execute_data* execute_data,
253 const char* function_name, 265 const char* function_name,
254 const zend_string* builtin_param, 266 const zend_string* builtin_param,
255 const char* builtin_param_name, 267 const char* builtin_param_name,
256 const sp_list_node* config, const HashTable* ht) { 268 const sp_list_node* config, const HashTable* ht) {
257 const sp_list_node* ht_entry = NULL; 269 const sp_list_node* ht_entry = NULL;
258 bool ret = false;
259 zend_string* current_filename; 270 zend_string* current_filename;
260 271
261 if (!execute_data) { 272 if (!execute_data) {
262 return false; // LCOV_EXCL_LINE 273 return; // LCOV_EXCL_LINE
263 } 274 }
264 275
265 if (UNEXPECTED(builtin_param && !strcmp(function_name, "eval"))) { 276 if (UNEXPECTED(builtin_param && !strcmp(function_name, "eval"))) {
@@ -271,24 +282,23 @@ bool should_disable_ht(zend_execute_data* execute_data,
271 282
272 ht_entry = zend_hash_str_find_ptr(ht, function_name, strlen(function_name)); 283 ht_entry = zend_hash_str_find_ptr(ht, function_name, strlen(function_name));
273 284
274 if (ht_entry && 285 if (ht_entry) {
275 should_disable(execute_data, function_name, builtin_param, 286 should_disable(execute_data, function_name, builtin_param,
276 builtin_param_name, ht_entry, current_filename)) { 287 builtin_param_name, ht_entry, current_filename);
277 ret = true;
278 } else if (config && config->data) { 288 } else if (config && config->data) {
279 ret = should_disable(execute_data, function_name, builtin_param, 289 should_disable(execute_data, function_name, builtin_param,
280 builtin_param_name, config, current_filename); 290 builtin_param_name, config, current_filename);
281 } 291 }
282 292
283 efree(current_filename); 293 efree(current_filename);
284 return ret;
285} 294}
286 295
287bool should_disable(zend_execute_data* execute_data, 296static void should_disable(zend_execute_data* execute_data,
288 const char* complete_function_path, 297 const char* complete_function_path,
289 const zend_string* builtin_param, 298 const zend_string* builtin_param,
290 const char* builtin_param_name, const sp_list_node* config, 299 const char* builtin_param_name,
291 const zend_string* current_filename) { 300 const sp_list_node* config,
301 const zend_string* current_filename) {
292 char current_file_hash[SHA256_SIZE * 2 + 1] = {0}; 302 char current_file_hash[SHA256_SIZE * 2 + 1] = {0};
293 303
294 while (config) { 304 while (config) {
@@ -381,7 +391,7 @@ bool should_disable(zend_execute_data* execute_data,
381 391
382 /* Everything matched.*/ 392 /* Everything matched.*/
383 if (true == config_node->allow) { 393 if (true == config_node->allow) {
384 goto allow; 394 return;
385 } 395 }
386 396
387 if (config_node->functions_list) { 397 if (config_node->functions_list) {
@@ -391,43 +401,34 @@ bool should_disable(zend_execute_data* execute_data,
391 sp_log_disable(complete_function_path, arg_name, arg_value_str, 401 sp_log_disable(complete_function_path, arg_name, arg_value_str,
392 config_node); 402 config_node);
393 } 403 }
394 if (true == config_node->simulation) { 404
395 goto next;
396 } else { // We've got a match, the function won't be executed
397 return true;
398 }
399 next: 405 next:
400 config = config->next; 406 config = config->next;
401 } 407 }
402allow:
403 return false;
404} 408}
405 409
406bool should_drop_on_ret_ht(const zval* return_value, const char* function_name, 410void should_drop_on_ret_ht(const zval* return_value, const char* function_name,
407 const sp_list_node* config, const HashTable* ht, 411 const sp_list_node* config, const HashTable* ht,
408 zend_execute_data* execute_data) { 412 zend_execute_data* execute_data) {
409 const sp_list_node* ht_entry = NULL; 413 const sp_list_node* ht_entry = NULL;
410 bool ret = false;
411 414
412 if (!function_name) { 415 if (!function_name) {
413 return ret; 416 return;
414 } 417 }
415 418
416 ht_entry = zend_hash_str_find_ptr(ht, function_name, strlen(function_name)); 419 ht_entry = zend_hash_str_find_ptr(ht, function_name, strlen(function_name));
417 420
418 if (ht_entry && 421 if (ht_entry) {
419 should_drop_on_ret(return_value, ht_entry, function_name, execute_data)) { 422 should_drop_on_ret(return_value, ht_entry, function_name, execute_data);
420 ret = true;
421 } else if (config && config->data) { 423 } else if (config && config->data) {
422 ret = should_drop_on_ret(return_value, config, function_name, execute_data); 424 should_drop_on_ret(return_value, config, function_name, execute_data);
423 } 425 }
424
425 return ret;
426} 426}
427 427
428bool should_drop_on_ret(const zval* return_value, const sp_list_node* config, 428static void should_drop_on_ret(const zval* return_value,
429 const char* complete_function_path, 429 const sp_list_node* config,
430 zend_execute_data* execute_data) { 430 const char* complete_function_path,
431 zend_execute_data* execute_data) {
431 const char* current_filename = zend_get_executed_filename(TSRMLS_C); 432 const char* current_filename = zend_get_executed_filename(TSRMLS_C);
432 char current_file_hash[SHA256_SIZE * 2 + 1] = {0}; 433 char current_file_hash[SHA256_SIZE * 2 + 1] = {0};
433 bool match_type = false, match_value = false; 434 bool match_type = false, match_value = false;
@@ -487,41 +488,34 @@ bool should_drop_on_ret(const zval* return_value, const sp_list_node* config,
487 488
488 if (true == match_type || true == match_value) { 489 if (true == match_type || true == match_value) {
489 if (true == config_node->allow) { 490 if (true == config_node->allow) {
490 return false; 491 return;
491 } 492 }
492 sp_log_disable_ret(complete_function_path, ret_value_str, config_node); 493 sp_log_disable_ret(complete_function_path, ret_value_str, config_node);
493 if (false == config_node->simulation) {
494 return true;
495 }
496 } 494 }
497 next: 495 next:
498 config = config->next; 496 config = config->next;
499 } 497 }
500 return false;
501} 498}
502 499
503ZEND_FUNCTION(check_disabled_function) { 500ZEND_FUNCTION(check_disabled_function) {
504 zif_handler orig_handler; 501 zif_handler orig_handler;
505 const char* current_function_name = get_active_function_name(TSRMLS_C); 502 const char* current_function_name = get_active_function_name(TSRMLS_C);
506 503
507 if (true == should_disable_ht( 504 should_disable_ht(
508 execute_data, current_function_name, NULL, NULL, 505 execute_data, current_function_name, NULL, NULL,
509 SNUFFLEUPAGUS_G(config) 506 SNUFFLEUPAGUS_G(config).config_disabled_functions_reg->disabled_functions,
510 .config_disabled_functions_reg->disabled_functions, 507 SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked);
511 SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked)) {
512 }
513 508
514 orig_handler = zend_hash_str_find_ptr( 509 orig_handler = zend_hash_str_find_ptr(
515 SNUFFLEUPAGUS_G(disabled_functions_hook), current_function_name, 510 SNUFFLEUPAGUS_G(disabled_functions_hook), current_function_name,
516 strlen(current_function_name)); 511 strlen(current_function_name));
517 orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); 512 orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
518 if (true == should_drop_on_ret_ht( 513 should_drop_on_ret_ht(
519 return_value, current_function_name, 514 return_value, current_function_name,
520 SNUFFLEUPAGUS_G(config) 515 SNUFFLEUPAGUS_G(config)
521 .config_disabled_functions_reg_ret->disabled_functions, 516 .config_disabled_functions_reg_ret->disabled_functions,
522 SNUFFLEUPAGUS_G(config).config_disabled_functions_ret_hooked, 517 SNUFFLEUPAGUS_G(config).config_disabled_functions_ret_hooked,
523 execute_data)) { 518 execute_data);
524 }
525} 519}
526 520
527static int hook_functions_regexp(const sp_list_node* config) { 521static int hook_functions_regexp(const sp_list_node* config) {