ce426f
commit bdf1ff052a8e23d637f2c838fa5642d78fcedc33
ce426f
Author: Paul Pluzhnikov <ppluzhnikov@google.com>
ce426f
Date:   Sun Feb 22 12:01:47 2015 -0800
ce426f
ce426f
    Fix BZ #17269 -- _IO_wstr_overflow integer overflow
ce426f
ce426f
diff --git a/libio/wstrops.c b/libio/wstrops.c
ce426f
index 43d847d..3993579 100644
ce426f
--- a/libio/wstrops.c
ce426f
+++ b/libio/wstrops.c
ce426f
@@ -95,8 +95,11 @@ _IO_wstr_overflow (fp, c)
ce426f
 	  wchar_t *old_buf = fp->_wide_data->_IO_buf_base;
ce426f
 	  size_t old_wblen = _IO_wblen (fp);
ce426f
 	  _IO_size_t new_size = 2 * old_wblen + 100;
ce426f
-	  if (new_size < old_wblen)
ce426f
+
ce426f
+	  if (__glibc_unlikely (new_size < old_wblen)
ce426f
+	      || __glibc_unlikely (new_size > SIZE_MAX / sizeof (wchar_t)))
ce426f
 	    return EOF;
ce426f
+
ce426f
 	  new_buf
ce426f
 	    = (wchar_t *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (new_size
ce426f
 									* sizeof (wchar_t));
ce426f
@@ -186,6 +189,9 @@ enlarge_userbuf (_IO_FILE *fp, _IO_off64_t offset, int reading)
ce426f
     return 1;
ce426f
 
ce426f
   _IO_size_t newsize = offset + 100;
ce426f
+  if (__glibc_unlikely (newsize > SIZE_MAX / sizeof (wchar_t)))
ce426f
+    return 1;
ce426f
+
ce426f
   wchar_t *oldbuf = wd->_IO_buf_base;
ce426f
   wchar_t *newbuf
ce426f
     = (wchar_t *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (newsize