com php-src: Throw warnings when using zero modulus in gmp_powm: ext/gmp/gmp.c ext/gmp/tests/016.php t
| From: | Nikita Popov | Date: | Thu, 04 Sep 2014 18:55:09 +0000 |
| Subject: | com php-src: Throw warnings when using zero modulus in gmp_powm: ext/gmp/gmp.c ext/gmp/tests/016.php t | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-81425@lists.php.net to get a copy of this message | ||
Commit: 15c139b99a6a887e2a9e8e1a07632e390650bd13
Author: Nikita Popov <nikic@php.net> Thu, 4 Sep 2014 20:55:09 +0200
Parents: f10d194c8cece6e0d5d34d8be0ea669bc6319e88
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=15c139b99a6a887e2a9e8e1a07632e390650bd13
Log:
Throw warnings when using zero modulus in gmp_powm
Also fixes a leak in this case.
Changed paths:
M ext/gmp/gmp.c
M ext/gmp/tests/016.phpt
Diff:
diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c
index 619f1c3..bad610c 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 8a0b344..f5857b6 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)