com php-src: Check for string overflow: ext/standard/php_smar t_string.h
| From: | Stanislav Malyshev | Date: | Thu, 11 Aug 2016 06:46:33 +0000 |
| Subject: | com php-src: Check for string overflow: ext/standard/php_smar t_string.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-93863@lists.php.net to get a copy of this message | ||
Commit: 7bf6d985351ad92715b18692ba128842b725f1c0
Author: Stanislav Malyshev <stas@php.net> Wed, 10 Aug 2016 23:46:33 -0700
Parents: 4f6a97f5321ef617b98a1f79aac1ad447d13b2b4
Branches: PHP-7.0
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7bf6d985351ad92715b18692ba128842b725f1c0
Log:
Check for string overflow
Changed paths:
M ext/standard/php_smart_string.h
Diff:
diff --git a/ext/standard/php_smart_string.h b/ext/standard/php_smart_string.h
index a832376..1175d32 100644
--- a/ext/standard/php_smart_string.h
+++ b/ext/standard/php_smart_string.h
@@ -52,19 +52,22 @@
#define SMART_STRING_DO_REALLOC(d, what) \
(d)->c = SMART_STRING_REALLOC((d)->c, (d)->a + 1, (what))
-#define smart_string_alloc4(d, n, what, newlen) do { \
+#define smart_string_alloc4(d, n, what, newlen) do { \
if (!(d)->c) { \
(d)->len = 0; \
newlen = (n); \
- (d)->a = newlen < SMART_STRING_START_SIZE \
- ? SMART_STRING_START_SIZE \
- : newlen + SMART_STRING_PREALLOC; \
- SMART_STRING_DO_REALLOC(d, what); \
+ (d)->a = newlen < SMART_STRING_START_SIZE \
+ ? SMART_STRING_START_SIZE \
+ : newlen + SMART_STRING_PREALLOC; \
+ SMART_STRING_DO_REALLOC(d, what); \
} else { \
+ if(UNEXPECTED(n > SIZE_MAX - (d)->len)) { \
+ zend_error(E_ERROR, "String size overflow"); \
+ } \
newlen = (d)->len + (n); \
if (newlen >= (d)->a) { \
- (d)->a = newlen + SMART_STRING_PREALLOC; \
- SMART_STRING_DO_REALLOC(d, what); \
+ (d)->a = newlen + SMART_STRING_PREALLOC; \
+ SMART_STRING_DO_REALLOC(d, what); \
} \
} \
} while (0)