1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix GH-20006: Power of 0 of BcMath number causes UB

Closes GH-20007.
This commit is contained in:
Niels Dossche
2025-09-30 13:37:19 +02:00
parent 4ab1324a34
commit a380dcae4d
3 changed files with 25 additions and 1 deletions

3
NEWS
View File

@@ -5,6 +5,9 @@ PHP NEWS
- Core:
. Fix OSS-Fuzz #447521098 (Fatal error during sccp shift eval). (ilutov)
- BcMath:
. Fixed bug GH-20006 (Power of 0 of BcMath number causes UB). (nielsdos)
- Opcache:
. Fixed segfault in function JIT due to NAN to bool warning. (Girgias)

View File

@@ -193,7 +193,12 @@ bc_raise_status bc_raise(bc_num base, long exponent, bc_num *result, size_t scal
if (bc_is_zero(base)) {
/* If the exponent is negative, it divides by 0 */
return is_neg ? BC_RAISE_STATUS_DIVIDE_BY_ZERO : BC_RAISE_STATUS_OK;
if (is_neg) {
return BC_RAISE_STATUS_DIVIDE_BY_ZERO;
}
bc_free_num (result);
*result = bc_copy_num(BCG(_zero_));
return BC_RAISE_STATUS_OK;
}
/* check overflow */

View File

@@ -0,0 +1,16 @@
--TEST--
GH-20006 (Power of 0 of BcMath number causes crash)
--EXTENSIONS--
bcmath
--FILE--
<?php
$n = new BcMath\Number("0");
var_dump(pow($n, 2));
?>
--EXPECTF--
object(BcMath\Number)#%d (2) {
["value"]=>
string(1) "0"
["scale"]=>
int(0)
}