@@ -356,10 +356,10 @@ static zend_result shift_operator_helper(gmp_binary_ui_op_t op, zval *return_val
356356 shift = Z_LVAL_P (op2 );
357357 }
358358
359- if (shift < 0 ) {
359+ if (shift < 0 || shift > ULONG_MAX ) {
360360 zend_throw_error (
361- zend_ce_value_error , "%s must be greater than or equal to 0 " ,
362- opcode == ZEND_POW ? "Exponent" : "Shift"
361+ zend_ce_value_error , "%s must be between 0 and %lu " ,
362+ opcode == ZEND_POW ? "Exponent" : "Shift" , ULONG_MAX
363363 );
364364 ZVAL_UNDEF (return_value );
365365 return FAILURE ;
@@ -1087,11 +1087,6 @@ ZEND_FUNCTION(gmp_fact)
10871087 GMP_Z_PARAM_INTO_MPZ_PTR (gmpnum )
10881088 ZEND_PARSE_PARAMETERS_END ();
10891089
1090- if (mpz_sgn (gmpnum ) < 0 ) {
1091- zend_argument_value_error (1 , "must be greater than or equal to 0 ");
1092- RETURN_THROWS ();
1093- }
1094-
10951090 if (!mpz_fits_ulong_p (gmpnum )) {
10961091 zend_argument_value_error (1 , "must be between 0 and %lu ", ULONG_MAX );
10971092 RETURN_THROWS ();
@@ -1114,8 +1109,8 @@ ZEND_FUNCTION(gmp_binomial)
11141109 Z_PARAM_LONG (k )
11151110 ZEND_PARSE_PARAMETERS_END ();
11161111
1117- if (k < 0 ) {
1118- zend_argument_value_error (2 , "must be greater than or equal to 0 " );
1112+ if (k < 0 || k > ULONG_MAX ) {
1113+ zend_argument_value_error (2 , "must be between 0 and % lu ", ULONG_MAX );
11191114 RETURN_THROWS ();
11201115 }
11211116
@@ -1136,8 +1131,8 @@ ZEND_FUNCTION(gmp_pow)
11361131 Z_PARAM_LONG (exp )
11371132 ZEND_PARSE_PARAMETERS_END ();
11381133
1139- if (exp < 0 ) {
1140- zend_argument_value_error (2 , "must be greater than or equal to 0 " );
1134+ if (exp < 0 || exp > ULONG_MAX ) {
1135+ zend_argument_value_error (2 , "must be between 0 and % lu ", ULONG_MAX );
11411136 RETURN_THROWS ();
11421137 }
11431138
@@ -1163,7 +1158,7 @@ ZEND_FUNCTION(gmp_powm)
11631158 }
11641159
11651160 if (!mpz_cmp_ui (gmpnum_mod , 0 )) {
1166- zend_throw_exception_ex (zend_ce_division_by_zero_error , 0 , "Modulo by zero ");
1161+ zend_argument_error (zend_ce_division_by_zero_error , 3 , "Modulo by zero ");
11671162 RETURN_THROWS ();
11681163 }
11691164
@@ -1226,8 +1221,8 @@ ZEND_FUNCTION(gmp_root)
12261221 Z_PARAM_LONG (nth )
12271222 ZEND_PARSE_PARAMETERS_END ();
12281223
1229- if (nth <= 0 ) {
1230- zend_argument_value_error (2 , "must be greater than 0" );
1224+ if (nth <= 0 || nth > ULONG_MAX ) {
1225+ zend_argument_value_error (2 , "must be between 1 and %lu" , ULONG_MAX );
12311226 RETURN_THROWS ();
12321227 }
12331228
@@ -1253,8 +1248,8 @@ ZEND_FUNCTION(gmp_rootrem)
12531248 Z_PARAM_LONG (nth )
12541249 ZEND_PARSE_PARAMETERS_END ();
12551250
1256- if (nth <= 0 ) {
1257- zend_argument_value_error (2 , "must be greater than or equal to 1" );
1251+ if (nth <= 0 || nth > ULONG_MAX ) {
1252+ zend_argument_value_error (2 , "must be between 1 and %lu" , ULONG_MAX );
12581253 RETURN_THROWS ();
12591254 }
12601255
0 commit comments