diff options
| author | jvoisin | 2017-11-24 16:56:40 +0100 |
|---|---|---|
| committer | GitHub | 2017-11-24 16:56:40 +0100 |
| commit | 6f333da3373ecaf70f1c561d8f1b9d209c907586 (patch) | |
| tree | 17dab24b36cd167a406fe6de1d8325603dc3ddac /src/sp_harden_rand.c | |
| parent | 5a224ee0c92d1639395d6a0c629316ae64226125 (diff) | |
Fix harden_rand (#72)
This one was tricky.
It was a great half-hour of joy, full of macros, ctags, gdb, radare2, tears, hardcoded `int3`, … to finally find that php calls `return` when it fails to parse some parameters for various reasons, even if everything goes fine.
This must be a better way to do this, but this is good enough™ for now.
This closes #66
Diffstat (limited to 'src/sp_harden_rand.c')
| -rw-r--r-- | src/sp_harden_rand.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/sp_harden_rand.c b/src/sp_harden_rand.c index 2155e7e..812686e 100644 --- a/src/sp_harden_rand.c +++ b/src/sp_harden_rand.c | |||
| @@ -18,7 +18,12 @@ static void random_int_wrapper(INTERNAL_FUNCTION_PARAMETERS) { | |||
| 18 | // LCOV_EXCL_BR_START | 18 | // LCOV_EXCL_BR_START |
| 19 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 1, 1); | 19 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 1, 1); |
| 20 | Z_PARAM_LONG(min); | 20 | Z_PARAM_LONG(min); |
| 21 | ZEND_PARSE_PARAMETERS_END(); | 21 | /* ZEND_PARSE_PARAMETERS_END call ZEND_PARSE_PARAMETERS_END_EX with |
| 22 | * `return` as a callback. As we don't need to strictly parse all parameters, | ||
| 23 | * we call ZEMD_PARSE_PARAMETERS_END_EX with (void)0 as a callback. | ||
| 24 | * If things go wrong, `php_random_int_throw` will scream anyway. | ||
| 25 | * There might be a better way to do it, please tell us if you know. */ | ||
| 26 | ZEND_PARSE_PARAMETERS_END_EX((void)0); | ||
| 22 | // LCOV_EXCL_BR_END | 27 | // LCOV_EXCL_BR_END |
| 23 | max = PHP_MT_RAND_MAX; | 28 | max = PHP_MT_RAND_MAX; |
| 24 | break; | 29 | break; |
| @@ -27,7 +32,7 @@ static void random_int_wrapper(INTERNAL_FUNCTION_PARAMETERS) { | |||
| 27 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 0, 2); | 32 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 0, 2); |
| 28 | Z_PARAM_LONG(min); | 33 | Z_PARAM_LONG(min); |
| 29 | Z_PARAM_LONG(max); | 34 | Z_PARAM_LONG(max); |
| 30 | ZEND_PARSE_PARAMETERS_END(); | 35 | ZEND_PARSE_PARAMETERS_END_EX((void)0); |
| 31 | } | 36 | } |
| 32 | 37 | ||
| 33 | if (min > max) { | 38 | if (min > max) { |
