From 6f333da3373ecaf70f1c561d8f1b9d209c907586 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Fri, 24 Nov 2017 16:56:40 +0100 Subject: 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 --- src/sp_harden_rand.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') 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) { // LCOV_EXCL_BR_START ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 1, 1); Z_PARAM_LONG(min); - ZEND_PARSE_PARAMETERS_END(); + /* 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; @@ -27,7 +32,7 @@ static void random_int_wrapper(INTERNAL_FUNCTION_PARAMETERS) { ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 0, 2); Z_PARAM_LONG(min); Z_PARAM_LONG(max); - ZEND_PARSE_PARAMETERS_END(); + ZEND_PARSE_PARAMETERS_END_EX((void)0); } if (min > max) { -- cgit v1.3