diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-03-14 17:26:17 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-03-14 17:26:17 +0100 |
commit | 8bb5582751ab18937584fb50ea10539df251b810 (patch) | |
tree | 82c9db3a39433687c18760777cc81bb3190fa42e /ext/bcmath/libbcmath/src | |
parent | 9499484ed2f0377678b2b4d88573327ee0e4ce6d (diff) | |
parent | 217c05da527bcbc8230b96e236ae687447409936 (diff) | |
download | php-git-8bb5582751ab18937584fb50ea10539df251b810.tar.gz |
Merge branch 'PHP-7.3' into PHP-7.4
Diffstat (limited to 'ext/bcmath/libbcmath/src')
-rw-r--r-- | ext/bcmath/libbcmath/src/num2long.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/ext/bcmath/libbcmath/src/num2long.c b/ext/bcmath/libbcmath/src/num2long.c index 3974dcf286..9b6c0d6e8b 100644 --- a/ext/bcmath/libbcmath/src/num2long.c +++ b/ext/bcmath/libbcmath/src/num2long.c @@ -53,12 +53,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) |