Skip to content

Commit eb23c60

Browse files
cmb69smalyshev
authored andcommitted
Fix #78878: Buffer underflow in bc_shift_addsub
We must not rely on `isdigit()` to detect digits, since we only support decimal ASCII digits in the following processing.
1 parent b771a18 commit eb23c60

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

ext/bcmath/libbcmath/src/str2num.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ bc_str2num (bc_num *num, char *str, int scale)
5757
zero_int = FALSE;
5858
if ( (*ptr == '+') || (*ptr == '-')) ptr++; /* Sign */
5959
while (*ptr == '0') ptr++; /* Skip leading zeros. */
60-
while (isdigit((int)*ptr)) ptr++, digits++; /* digits */
60+
while (*ptr >= '0' && *ptr <= '9') ptr++, digits++; /* digits */
6161
if (*ptr == '.') ptr++; /* decimal point */
62-
while (isdigit((int)*ptr)) ptr++, strscale++; /* digits */
62+
while (*ptr >= '0' && *ptr <= '9') ptr++, strscale++; /* digits */
6363
if ((*ptr != '\0') || (digits+strscale == 0))
6464
{
6565
*num = bc_copy_num (BCG(_zero_));

ext/bcmath/tests/bug78878.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Bug #78878 (Buffer underflow in bc_shift_addsub)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
print @bcmul("\xB26483605105519922841849335928742092", bcpowmod(2, 65535, -4e-4));
10+
?>
11+
--EXPECT--
12+
bc math warning: non-zero scale in modulus
13+
0

0 commit comments

Comments
 (0)