Skip to content

Commit b9db724

Browse files
committed
Revert "merge errors"
This reverts commit 64756b2.
1 parent 64756b2 commit b9db724

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

ext/gmp/gmp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,11 @@ ZEND_FUNCTION(gmp_powm_sec)
12061206
RETURN_THROWS();
12071207
}
12081208

1209-
/* Zero is not odd, so this also rejects a zero modulus. */
1209+
if (!mpz_cmp_ui(gmpnum_mod, 0)) {
1210+
zend_argument_error(zend_ce_division_by_zero_error, 3, "Modulo by zero");
1211+
RETURN_THROWS();
1212+
}
1213+
12101214
if (!mpz_odd_p(gmpnum_mod)) {
12111215
zend_argument_value_error(3, "must be odd");
12121216
RETURN_THROWS();

ext/gmp/tests/gmp_powm_sec.phpt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ foreach ([0, -1] as $exp) {
2222
}
2323
}
2424

25-
foreach ([0, 496] as $modulus) {
26-
try {
27-
var_dump(gmp_powm_sec(4, 13, $modulus));
28-
} catch (\ValueError $e) {
29-
echo $e->getMessage(), \PHP_EOL;
30-
}
25+
try {
26+
var_dump(gmp_powm_sec(4, 13, 0));
27+
} catch (\DivisionByZeroError $e) {
28+
echo $e->getMessage(), \PHP_EOL;
29+
}
30+
31+
try {
32+
var_dump(gmp_powm_sec(4, 13, 496));
33+
} catch (\ValueError $e) {
34+
echo $e->getMessage(), \PHP_EOL;
3135
}
3236

3337
echo "Done\n";
@@ -37,6 +41,6 @@ string(3) "445"
3741
string(1) "5"
3842
gmp_powm_sec(): Argument #2 ($exponent) must be greater than 0
3943
gmp_powm_sec(): Argument #2 ($exponent) must be greater than 0
40-
gmp_powm_sec(): Argument #3 ($modulus) must be odd
44+
gmp_powm_sec(): Argument #3 ($modulus) Modulo by zero
4145
gmp_powm_sec(): Argument #3 ($modulus) must be odd
4246
Done

0 commit comments

Comments
 (0)