From: Nikita Popov Date: Thu, 4 Sep 2014 18:55:09 +0000 (+0200) Subject: Throw warnings when using zero modulus in gmp_powm X-Git-Tag: php-5.6.1RC1~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15c139b99a6a887e2a9e8e1a07632e390650bd13;p=php Throw warnings when using zero modulus in gmp_powm Also fixes a leak in this case. --- diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index 619f1c39c3..bad610c0b4 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -1484,10 +1484,9 @@ ZEND_FUNCTION(gmp_powm) FETCH_GMP_ZVAL_DEP_DEP(gmpnum_mod, mod_arg, temp_mod, temp_exp, temp_base); if (!mpz_cmp_ui(gmpnum_mod, 0)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Modulus may not be zero"); FREE_GMP_TEMP(temp_base); - if (use_ui) { - FREE_GMP_TEMP(temp_exp); - } + FREE_GMP_TEMP(temp_exp); FREE_GMP_TEMP(temp_mod); RETURN_FALSE; } diff --git a/ext/gmp/tests/016.phpt b/ext/gmp/tests/016.phpt index 8a0b34458f..f5857b6995 100644 --- a/ext/gmp/tests/016.phpt +++ b/ext/gmp/tests/016.phpt @@ -19,6 +19,9 @@ var_dump(gmp_strval(gmp_powm($n,$e,1000))); $m = gmp_init(900); var_dump(gmp_strval(gmp_powm($n,$e,$m))); +var_dump(gmp_powm(5, 11, 0)); +var_dump(gmp_powm(5, "11", gmp_init(0))); + var_dump(gmp_powm(array(),$e,$m)); var_dump(gmp_powm($n,array(),$m)); var_dump(gmp_powm($n,$e,array())); @@ -46,6 +49,12 @@ string(3) "331" string(3) "171" string(3) "371" +Warning: gmp_powm(): Modulus may not be zero in %s on line %d +bool(false) + +Warning: gmp_powm(): Modulus may not be zero in %s on line %d +bool(false) + Warning: gmp_powm(): Unable to convert variable to GMP - wrong type in %s on line %d bool(false)