diff options
author | Anatol Belski <ab@php.net> | 2016-04-27 11:45:29 +0200 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2016-04-27 11:45:29 +0200 |
commit | 33d41da3474729486d6bbb7fb13e1b697356481e (patch) | |
tree | 1bcd2ca85319bddc3731738e07fc77fa9f1d01cf /ext/bcmath/bcmath.c | |
parent | a32e143d4eb185f9b666ef1cd93761b2baafec28 (diff) | |
parent | e315a162da99f59e82a5272714a6f3d4d724b037 (diff) | |
download | php-git-33d41da3474729486d6bbb7fb13e1b697356481e.tar.gz |
Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
Fix memory leak
Fix bug #72099: xml_parse_into_struct segmentation fault
5.5.36 now
Fix bug #72094 - Out of bounds heap read access in exif header processing
Fix bug #72093: bcpowmod accepts negative scale and corrupts _one_ definition
Fix bug #72061 - Out-of-bounds reads in zif_grapheme_stripos with negative offset
Fix for bug #71912 (libgd: signedness vulnerability)
Typo in NEWS
Diffstat (limited to 'ext/bcmath/bcmath.c')
-rw-r--r-- | ext/bcmath/bcmath.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/ext/bcmath/bcmath.c b/ext/bcmath/bcmath.c index fd14050f05..7100367faa 100644 --- a/ext/bcmath/bcmath.c +++ b/ext/bcmath/bcmath.c @@ -207,6 +207,21 @@ static void php_str2num(bc_num *num, char *str) } /* }}} */ +/* {{{ split_bc_num + Convert to bc_num detecting scale */ +static bc_num split_bc_num(bc_num num) { + bc_num newnum; + if (num->n_refs >= 1) { + return num; + } + newnum = _bc_new_num_ex(0, 0, 0); + *newnum = *num; + newnum->n_refs = 1; + num->n_refs--; + return newnum; +} +/* }}} */ + /* {{{ proto string bcadd(string left_operand, string right_operand [, int scale]) Returns the sum of two arbitrary precision numbers */ PHP_FUNCTION(bcadd) @@ -233,6 +248,7 @@ PHP_FUNCTION(bcadd) bc_add (first, second, &result, scale); if (result->n_scale > scale) { + result = split_bc_num(result); result->n_scale = scale; } @@ -270,6 +286,7 @@ PHP_FUNCTION(bcsub) bc_sub (first, second, &result, scale); if (result->n_scale > scale) { + result = split_bc_num(result); result->n_scale = scale; } @@ -307,6 +324,7 @@ PHP_FUNCTION(bcmul) bc_multiply (first, second, &result, scale); if (result->n_scale > scale) { + result = split_bc_num(result); result->n_scale = scale; } @@ -345,6 +363,7 @@ PHP_FUNCTION(bcdiv) switch (bc_divide(first, second, &result, scale)) { case 0: /* OK */ if (result->n_scale > scale) { + result = split_bc_num(result); result->n_scale = scale; } RETVAL_STR(bc_num2str(result)); @@ -462,6 +481,7 @@ PHP_FUNCTION(bcpow) bc_raise (first, second, &result, scale); if (result->n_scale > scale) { + result = split_bc_num(result); result->n_scale = scale; } @@ -496,6 +516,7 @@ PHP_FUNCTION(bcsqrt) if (bc_sqrt (&result, scale) != 0) { if (result->n_scale > scale) { + result = split_bc_num(result); result->n_scale = scale; } RETVAL_STR(bc_num2str(result)); |