From 4f1dc0debc8eb7be9d1ed498f0b8dd64021662e7 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 29 Nov 2017 17:53:06 +0100 Subject: Code formatting pass on harden-rand --- src/sp_harden_rand.c | 72 +++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 32 deletions(-) (limited to 'src/sp_harden_rand.c') diff --git a/src/sp_harden_rand.c b/src/sp_harden_rand.c index 4b6fa18..b84fbe3 100644 --- a/src/sp_harden_rand.c +++ b/src/sp_harden_rand.c @@ -12,38 +12,39 @@ static void random_int_wrapper(INTERNAL_FUNCTION_PARAMETERS) { zend_long result; switch (EX_NUM_ARGS()) { - case 0: - min = 0; - max = PHP_MT_RAND_MAX; - break; - case 1: - // LCOV_EXCL_BR_START - ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 1, 1); - Z_PARAM_LONG(min); - /* ZEND_PARSE_PARAMETERS_END call ZEND_PARSE_PARAMETERS_END_EX with - * `return` as a callback. As we don't need to strictly parse all parameters, - * we call ZEMD_PARSE_PARAMETERS_END_EX with (void)0 as a callback. - * If things go wrong, `php_random_int_throw` will scream anyway. - * There might be a better way to do it, please tell us if you know. */ - ZEND_PARSE_PARAMETERS_END_EX((void)0); - // LCOV_EXCL_BR_END - max = PHP_MT_RAND_MAX; - break; - case 2: - default: - ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 0, 2); - Z_PARAM_LONG(min); - Z_PARAM_LONG(max); - ZEND_PARSE_PARAMETERS_END_EX((void)0); + case 0: + min = 0; + max = PHP_MT_RAND_MAX; + break; + case 1: + // LCOV_EXCL_BR_START + ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 1, 1); + Z_PARAM_LONG(min); + /* ZEND_PARSE_PARAMETERS_END call ZEND_PARSE_PARAMETERS_END_EX with + * `return` as a callback. As we don't need to strictly parse all + * parameters, + * we call ZEMD_PARSE_PARAMETERS_END_EX with (void)0 as a callback. + * If things go wrong, `php_random_int_throw` will scream anyway. + * There might be a better way to do it, please tell us if you know. */ + ZEND_PARSE_PARAMETERS_END_EX((void)0); + // LCOV_EXCL_BR_END + max = PHP_MT_RAND_MAX; + break; + case 2: + default: + ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 0, 2); + Z_PARAM_LONG(min); + Z_PARAM_LONG(max); + ZEND_PARSE_PARAMETERS_END_EX((void)0); } if (min > max) { if (php_random_int_throw(max, min, &result) == FAILURE) { - return; + return; // LCOV_EXCL_LINE } } else { if (php_random_int_throw(min, max, &result) == FAILURE) { - return; + return; // LCOV_EXCL_LINE } } @@ -53,13 +54,16 @@ static void random_int_wrapper(INTERNAL_FUNCTION_PARAMETERS) { PHP_FUNCTION(sp_rand) { void (*orig_handler)(INTERNAL_FUNCTION_PARAMETERS); - if ((orig_handler = zend_hash_str_find_ptr(SNUFFLEUPAGUS_G(sp_internal_functions_hook), "rand", - strlen("rand")))) { + if ((orig_handler = + zend_hash_str_find_ptr(SNUFFLEUPAGUS_G(sp_internal_functions_hook), + "rand", strlen("rand")))) { /* call the original `rand` function, * since we might no be the only ones to hook it*/ orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); } else { - sp_log_err("harden_rand", "Unable to find the pointer to the original function 'rand' in the hashtable.\n"); + sp_log_err("harden_rand", + "Unable to find the pointer to the original function 'rand' in " + "the hashtable.\n"); } random_int_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU); } @@ -67,13 +71,16 @@ PHP_FUNCTION(sp_rand) { PHP_FUNCTION(sp_mt_rand) { void (*orig_handler)(INTERNAL_FUNCTION_PARAMETERS); - if ((orig_handler = zend_hash_str_find_ptr(SNUFFLEUPAGUS_G(sp_internal_functions_hook), - "mt_rand", strlen("mt_rand")))) { + if ((orig_handler = + zend_hash_str_find_ptr(SNUFFLEUPAGUS_G(sp_internal_functions_hook), + "mt_rand", strlen("mt_rand")))) { /* call the original `mt_rand` function, * since we might no be the only ones to hook it*/ orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); } else { - sp_log_err("harden_rand", "Unable to find the pointer to the original function 'mt_rand' in the hashtable.\n"); + sp_log_err("harden_rand", + "Unable to find the pointer to the original function 'mt_rand' " + "in the hashtable.\n"); } random_int_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU); } @@ -82,7 +89,8 @@ int hook_rand() { TSRMLS_FETCH(); HOOK_FUNCTION("rand", sp_internal_functions_hook, PHP_FN(sp_rand), false); - HOOK_FUNCTION("mt_rand", sp_internal_functions_hook, PHP_FN(sp_mt_rand), false); + HOOK_FUNCTION("mt_rand", sp_internal_functions_hook, PHP_FN(sp_mt_rand), + false); return SUCCESS; } -- cgit v1.3