com php-src: Simplified integer overflow checks: Zend/zend_al loc.c
| From: | Dmitry Stogov | Date: | Fri, 28 Aug 2015 09:47:21 +0000 |
| Subject: | com php-src: Simplified integer overflow checks: Zend/zend_al loc.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-88791@lists.php.net to get a copy of this message | ||
Commit: 87f0f77105eb940d0eca63b7c889c136e9ce2a48
Author: Dmitry Stogov <dmitry@zend.com> Fri, 28 Aug 2015 12:47:21 +0300
Parents: 5d15d2b26d01ec267234b26abad6be4e04b364ac
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=87f0f77105eb940d0eca63b7c889c136e9ce2a48
Log:
Simplified integer overflow checks
Changed paths:
M Zend/zend_alloc.c
Diff:
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c
index 23ec7bc..c30d26b 100644
--- a/Zend/zend_alloc.c
+++ b/Zend/zend_alloc.c
@@ -2486,7 +2486,10 @@ ZEND_API char* ZEND_FASTCALL _estrdup(const char *s ZEND_FILE_LINE_DC
ZEND_FILE_
char *p;
length = strlen(s);
- p = (char *) _emalloc(safe_address(length, 1, 1) ZEND_FILE_LINE_RELAY_CC
ZEND_FILE_LINE_ORIG_RELAY_CC);
+ if (UNEXPECTED(length + 1 == 0)) {
+ zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu +
%zu)", 1, length, 1);
+ }
+ p = (char *) _emalloc(length + 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
if (UNEXPECTED(p == NULL)) {
return p;
}
@@ -2498,7 +2501,10 @@ ZEND_API char* ZEND_FASTCALL _estrndup(const char *s, size_t length
ZEND_FILE_LI
{
char *p;
- p = (char *) _emalloc(safe_address(length, 1, 1) ZEND_FILE_LINE_RELAY_CC
ZEND_FILE_LINE_ORIG_RELAY_CC);
+ if (UNEXPECTED(length + 1 == 0)) {
+ zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu +
%zu)", 1, length, 1);
+ }
+ p = (char *) _emalloc(length + 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
if (UNEXPECTED(p == NULL)) {
return p;
}
@@ -2512,7 +2518,10 @@ ZEND_API char* ZEND_FASTCALL zend_strndup(const char *s, size_t length)
{
char *p;
- p = (char *) malloc(safe_address(length, 1, 1));
+ if (UNEXPECTED(length + 1 == 0)) {
+ zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu +
%zu)", 1, length, 1);
+ }
+ p = (char *) malloc(length + 1);
if (UNEXPECTED(p == NULL)) {
return p;
}