diff options
| author | jvoisin | 2017-11-29 17:53:06 +0100 |
|---|---|---|
| committer | jvoisin | 2017-11-29 17:53:06 +0100 |
| commit | 4f1dc0debc8eb7be9d1ed498f0b8dd64021662e7 (patch) | |
| tree | 5bab5e0cac44545b22111bdae587e11d76291c38 | |
| parent | d7c093136398157bba2de954b278c7e55cb74f57 (diff) | |
Code formatting pass on harden-rand
| -rw-r--r-- | src/sp_harden_rand.c | 72 |
1 files changed, 40 insertions, 32 deletions
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) { | |||
| 12 | zend_long result; | 12 | zend_long result; |
| 13 | 13 | ||
| 14 | switch (EX_NUM_ARGS()) { | 14 | switch (EX_NUM_ARGS()) { |
| 15 | case 0: | 15 | case 0: |
| 16 | min = 0; | 16 | min = 0; |
| 17 | max = PHP_MT_RAND_MAX; | 17 | max = PHP_MT_RAND_MAX; |
| 18 | break; | 18 | break; |
| 19 | case 1: | 19 | case 1: |
| 20 | // LCOV_EXCL_BR_START | 20 | // LCOV_EXCL_BR_START |
| 21 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 1, 1); | 21 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 1, 1); |
| 22 | Z_PARAM_LONG(min); | 22 | Z_PARAM_LONG(min); |
| 23 | /* ZEND_PARSE_PARAMETERS_END call ZEND_PARSE_PARAMETERS_END_EX with | 23 | /* ZEND_PARSE_PARAMETERS_END call ZEND_PARSE_PARAMETERS_END_EX with |
| 24 | * `return` as a callback. As we don't need to strictly parse all parameters, | 24 | * `return` as a callback. As we don't need to strictly parse all |
| 25 | * we call ZEMD_PARSE_PARAMETERS_END_EX with (void)0 as a callback. | 25 | * parameters, |
| 26 | * If things go wrong, `php_random_int_throw` will scream anyway. | 26 | * we call ZEMD_PARSE_PARAMETERS_END_EX with (void)0 as a callback. |
| 27 | * There might be a better way to do it, please tell us if you know. */ | 27 | * If things go wrong, `php_random_int_throw` will scream anyway. |
| 28 | ZEND_PARSE_PARAMETERS_END_EX((void)0); | 28 | * There might be a better way to do it, please tell us if you know. */ |
| 29 | // LCOV_EXCL_BR_END | 29 | ZEND_PARSE_PARAMETERS_END_EX((void)0); |
| 30 | max = PHP_MT_RAND_MAX; | 30 | // LCOV_EXCL_BR_END |
| 31 | break; | 31 | max = PHP_MT_RAND_MAX; |
| 32 | case 2: | 32 | break; |
| 33 | default: | 33 | case 2: |
| 34 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 0, 2); | 34 | default: |
| 35 | Z_PARAM_LONG(min); | 35 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 0, 2); |
| 36 | Z_PARAM_LONG(max); | 36 | Z_PARAM_LONG(min); |
| 37 | ZEND_PARSE_PARAMETERS_END_EX((void)0); | 37 | Z_PARAM_LONG(max); |
| 38 | ZEND_PARSE_PARAMETERS_END_EX((void)0); | ||
| 38 | } | 39 | } |
| 39 | 40 | ||
| 40 | if (min > max) { | 41 | if (min > max) { |
| 41 | if (php_random_int_throw(max, min, &result) == FAILURE) { | 42 | if (php_random_int_throw(max, min, &result) == FAILURE) { |
| 42 | return; | 43 | return; // LCOV_EXCL_LINE |
| 43 | } | 44 | } |
| 44 | } else { | 45 | } else { |
| 45 | if (php_random_int_throw(min, max, &result) == FAILURE) { | 46 | if (php_random_int_throw(min, max, &result) == FAILURE) { |
| 46 | return; | 47 | return; // LCOV_EXCL_LINE |
| 47 | } | 48 | } |
| 48 | } | 49 | } |
| 49 | 50 | ||
| @@ -53,13 +54,16 @@ static void random_int_wrapper(INTERNAL_FUNCTION_PARAMETERS) { | |||
| 53 | PHP_FUNCTION(sp_rand) { | 54 | PHP_FUNCTION(sp_rand) { |
| 54 | void (*orig_handler)(INTERNAL_FUNCTION_PARAMETERS); | 55 | void (*orig_handler)(INTERNAL_FUNCTION_PARAMETERS); |
| 55 | 56 | ||
| 56 | if ((orig_handler = zend_hash_str_find_ptr(SNUFFLEUPAGUS_G(sp_internal_functions_hook), "rand", | 57 | if ((orig_handler = |
| 57 | strlen("rand")))) { | 58 | zend_hash_str_find_ptr(SNUFFLEUPAGUS_G(sp_internal_functions_hook), |
| 59 | "rand", strlen("rand")))) { | ||
| 58 | /* call the original `rand` function, | 60 | /* call the original `rand` function, |
| 59 | * since we might no be the only ones to hook it*/ | 61 | * since we might no be the only ones to hook it*/ |
| 60 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 62 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 61 | } else { | 63 | } else { |
| 62 | sp_log_err("harden_rand", "Unable to find the pointer to the original function 'rand' in the hashtable.\n"); | 64 | sp_log_err("harden_rand", |
| 65 | "Unable to find the pointer to the original function 'rand' in " | ||
| 66 | "the hashtable.\n"); | ||
| 63 | } | 67 | } |
| 64 | random_int_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 68 | random_int_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 65 | } | 69 | } |
| @@ -67,13 +71,16 @@ PHP_FUNCTION(sp_rand) { | |||
| 67 | PHP_FUNCTION(sp_mt_rand) { | 71 | PHP_FUNCTION(sp_mt_rand) { |
| 68 | void (*orig_handler)(INTERNAL_FUNCTION_PARAMETERS); | 72 | void (*orig_handler)(INTERNAL_FUNCTION_PARAMETERS); |
| 69 | 73 | ||
| 70 | if ((orig_handler = zend_hash_str_find_ptr(SNUFFLEUPAGUS_G(sp_internal_functions_hook), | 74 | if ((orig_handler = |
| 71 | "mt_rand", strlen("mt_rand")))) { | 75 | zend_hash_str_find_ptr(SNUFFLEUPAGUS_G(sp_internal_functions_hook), |
| 76 | "mt_rand", strlen("mt_rand")))) { | ||
| 72 | /* call the original `mt_rand` function, | 77 | /* call the original `mt_rand` function, |
| 73 | * since we might no be the only ones to hook it*/ | 78 | * since we might no be the only ones to hook it*/ |
| 74 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 79 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 75 | } else { | 80 | } else { |
| 76 | sp_log_err("harden_rand", "Unable to find the pointer to the original function 'mt_rand' in the hashtable.\n"); | 81 | sp_log_err("harden_rand", |
| 82 | "Unable to find the pointer to the original function 'mt_rand' " | ||
| 83 | "in the hashtable.\n"); | ||
| 77 | } | 84 | } |
| 78 | random_int_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU); | 85 | random_int_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 79 | } | 86 | } |
| @@ -82,7 +89,8 @@ int hook_rand() { | |||
| 82 | TSRMLS_FETCH(); | 89 | TSRMLS_FETCH(); |
| 83 | 90 | ||
| 84 | HOOK_FUNCTION("rand", sp_internal_functions_hook, PHP_FN(sp_rand), false); | 91 | HOOK_FUNCTION("rand", sp_internal_functions_hook, PHP_FN(sp_rand), false); |
| 85 | HOOK_FUNCTION("mt_rand", sp_internal_functions_hook, PHP_FN(sp_mt_rand), false); | 92 | HOOK_FUNCTION("mt_rand", sp_internal_functions_hook, PHP_FN(sp_mt_rand), |
| 93 | false); | ||
| 86 | 94 | ||
| 87 | return SUCCESS; | 95 | return SUCCESS; |
| 88 | } | 96 | } |
