com php-src: Revert "Fix for #73240 - Write out of bounds at number_format": ext/standard/math.c
| From: | Anatol Belski | Date: | Wed, 12 Oct 2016 14:12:18 +0000 |
| Subject: | com php-src: Revert "Fix for #73240 - Write out of bounds at number_format": ext/standard/math.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94941@lists.php.net to get a copy of this message | ||
Commit: 80eb013a926fad18cb0da05c508f564da3c1d88c
Author: Anatol Belski <ab@php.net> Wed, 12 Oct 2016 16:11:32 +0200
Parents: b135ba3fa93fd4f085322573d2850b29cb662e21
Branches: PHP-7.0 PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=80eb013a926fad18cb0da05c508f564da3c1d88c
Log:
Revert "Fix for #73240 - Write out of bounds at number_format"
This reverts commit 01280f8deb837a61237a619cffa886d7f8c31963.
The fix is already merged by Stas.
Bugs:
https://bugs.php.net/73240
Changed paths:
M ext/standard/math.c
Diff:
diff --git a/ext/standard/math.c b/ext/standard/math.c
index 62f6ea9..e4b1160 100644
--- a/ext/standard/math.c
+++ b/ext/standard/math.c
@@ -1151,14 +1151,18 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char
*dec_poin
/* calculate the length of the return buffer */
if (dp) {
- integral = (dp - ZSTR_VAL(tmpbuf));
+ integral = (int)(dp - ZSTR_VAL(tmpbuf));
} else {
/* no decimal point was found */
- integral = ZSTR_LEN(tmpbuf);
+ integral = (int)ZSTR_LEN(tmpbuf);
}
/* allow for thousand separators */
if (thousand_sep) {
+ if (integral + thousand_sep_len * ((integral-1) / 3) < integral) {
+ /* overflow */
+ php_error_docref(NULL, E_ERROR, "String overflow");
+ }
integral += thousand_sep_len * ((integral-1) / 3);
}
@@ -1168,6 +1172,10 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char
*dec_poin
reslen += dec;
if (dec_point) {
+ if (reslen + dec_point_len < dec_point_len) {
+ /* overflow */
+ php_error_docref(NULL, E_ERROR, "String overflow");
+ }
reslen += dec_point_len;
}
}
@@ -1270,7 +1278,6 @@ PHP_FUNCTION(number_format)
break;
default:
WRONG_PARAM_COUNT;
- break;
}
}
/* }}} */