summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-03-14 17:25:44 +0100
committerNikita Popov <nikita.ppv@gmail.com>2019-03-14 17:25:54 +0100
commit217c05da527bcbc8230b96e236ae687447409936 (patch)
treee8b0406ec398054049eb5dab4c0f91e70ddc4704
parent82174e68b6065e8593c2cf8da86841b36037d166 (diff)
parente7d40afb7a7984174eb132a14b7a6621c8e76258 (diff)
downloadphp-git-217c05da527bcbc8230b96e236ae687447409936.tar.gz
Merge branch 'PHP-7.2' into PHP-7.3
-rw-r--r--NEWS4
-rw-r--r--ext/bcmath/libbcmath/src/num2long.c17
2 files changed, 16 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index 6ddf1be1a0..09dbf64b56 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,10 @@ PHP NEWS
. Fixed bug #77345 (Stack Overflow caused by circular reference in garbage
collection). (Alexandru Patranescu, Nikita, Dmitry)
+- Bcmath:
+ . Fixed bug #77742 (bcpow() implementation related to gcc compiler
+ optimization). (Nikita)
+
- CLI Server:
. Fixed bug #77722 (Incorrect IP set to $_SERVER['REMOTE_ADDR'] on the
localhost). (Nikita)
diff --git a/ext/bcmath/libbcmath/src/num2long.c b/ext/bcmath/libbcmath/src/num2long.c
index 81e82a6fac..228f6645a2 100644
--- a/ext/bcmath/libbcmath/src/num2long.c
+++ b/ext/bcmath/libbcmath/src/num2long.c
@@ -54,12 +54,19 @@ bc_num2long (num)
/* Extract the int value, ignore the fraction. */
val = 0;
nptr = num->n_value;
- for (index=num->n_len; (index>0) && (val<=(LONG_MAX/BASE)); index--)
- val = val*BASE + *nptr++;
+ for (index = num->n_len; index > 0; index--) {
+ char n = *nptr++;
- /* Check for overflow. If overflow, return zero. */
- if (index>0) val = 0;
- if (val < 0) val = 0;
+ if (val > LONG_MAX/BASE) {
+ return 0;
+ }
+ val *= BASE;
+
+ if (val > LONG_MAX - n) {
+ return 0;
+ }
+ val += n;
+ }
/* Return the value. */
if (num->n_sign == PLUS)