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