Throw warnings when using zero modulus in gmp_powm

Also fixes a leak in this case.
This commit is contained in:
Nikita Popov 2014-09-04 20:55:09 +02:00
parent f10d194c8c
commit 15c139b99a
2 changed files with 11 additions and 3 deletions

View File

@ -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;
}

View File

@ -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)