]> granicus.if.org Git - php/commitdiff
Fix bug #72275: don't allow smart_str to overflow int
authorStanislav Malyshev <stas@php.net>
Tue, 14 Jun 2016 06:12:47 +0000 (23:12 -0700)
committerStanislav Malyshev <stas@php.net>
Tue, 14 Jun 2016 07:02:17 +0000 (00:02 -0700)
ext/standard/php_smart_str.h

index 1872fa8647dd48d9aeb1cc5f68e82b3c33bf488c..fc1a753dd5b323a04cae27e73aa7495d8d30deff 100644 (file)
@@ -63,6 +63,9 @@
                newlen = (d)->len + (n);                                                                        \
                if (newlen >= (d)->a) {                                                                         \
                        (d)->a = newlen + SMART_STR_PREALLOC;                                   \
+               if (UNEXPECTED((d)->a >= INT_MAX)) {                                    \
+                zend_error(E_ERROR, "String size overflow");           \
+            }                                                                                                          \
                        SMART_STR_DO_REALLOC(d, what);                                                  \
                }                                                                                                                       \
        }                                                                                                                               \
  * for GCC compatible compilers, e.g.
  *
  * #define f(..) ({char *r;..;__r;})
- */  
+ */
+
 static inline char *smart_str_print_long(char *buf, long num) {
-       char *r; 
-       smart_str_print_long4(buf, num, unsigned long, r); 
+       char *r;
+       smart_str_print_long4(buf, num, unsigned long, r);
        return r;
 }
 
 static inline char *smart_str_print_unsigned(char *buf, long num) {
-       char *r; 
-       smart_str_print_unsigned4(buf, num, unsigned long, r); 
+       char *r;
+       smart_str_print_unsigned4(buf, num, unsigned long, r);
        return r;
 }
 
@@ -168,7 +171,7 @@ static inline char *smart_str_print_unsigned(char *buf, long num) {
        smart_str_print##func##4 (__b + sizeof(__b) - 1, (num), vartype, __t);  \
        smart_str_appendl_ex((dest), __t, __b + sizeof(__b) - 1 - __t, (type)); \
 } while (0)
-       
+
 #define smart_str_append_unsigned_ex(dest, num, type) \
        smart_str_append_generic_ex((dest), (num), (type), unsigned long, _unsigned)