diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index 202713f63569c..d48c4cf077f9f 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -1290,6 +1290,7 @@ ZEND_FUNCTION(gmp_pow) INIT_GMP_RETVAL(gmpnum_result); gmpnum = mpz_get_ui(gmpnum_base); if ((log10(gmpnum) * exp) > (double)ULONG_MAX) { + FREE_GMP_TEMP(temp_base); zend_value_error("base and exponent overflow"); RETURN_THROWS(); } diff --git a/ext/gmp/tests/gmp_pow_fpe.phpt b/ext/gmp/tests/gmp_pow_fpe.phpt new file mode 100644 index 0000000000000..591107467f386 --- /dev/null +++ b/ext/gmp/tests/gmp_pow_fpe.phpt @@ -0,0 +1,22 @@ +--TEST-- +gmp_pow() floating point exception +--EXTENSIONS-- +gmp +--FILE-- +getMessage() . PHP_EOL; +} +try { + gmp_pow(256, PHP_INT_MAX); +} catch (\ValueError $e) { + echo $e->getMessage(); +} +?> +--EXPECT-- +base and exponent overflow +base and exponent overflow