]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix BZ #17269 -- _IO_wstr_overflow integer overflow
authorPaul Pluzhnikov <ppluzhnikov@google.com>
Sun, 22 Feb 2015 20:01:47 +0000 (12:01 -0800)
committerAurelien Jarno <aurelien@aurel32.net>
Mon, 19 Oct 2015 08:45:23 +0000 (10:45 +0200)
(cherry picked from commit bdf1ff052a8e23d637f2c838fa5642d78fcedc33)

Conflicts:
ChangeLog
NEWS

ChangeLog
NEWS
libio/wstrops.c

index a4f4e0d863a6e7681d9ffc30a2206eda60ff2ded..8d621b240b8a600b43cb93a6212998e1a03d1444 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-02-22  Paul Pluzhnikov  <ppluzhnikov@google.com>
+
+       [BZ #17269]
+       * libio/wstrops.c (_IO_wstr_overflow): Guard against integer overflow
+       (enlarge_userbuf): Likewise.
+
 2015-02-26  Andreas Schwab  <schwab@suse.de>
 
        [BZ #18032]
diff --git a/NEWS b/NEWS
index c017fa30140d28f896271529004beab32f103446..9e7316b4a77f6cc3eba0b3505c12569c083a0bd4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,7 +11,7 @@ Version 2.19.1
 
   15946, 16545, 16574, 16623, 16657, 16695, 16743, 16878, 16882, 16885,
   16916, 16932, 16943, 16958, 17048, 17069, 17079, 17137, 17153, 17213,
-  17263, 17325, 17555, 18032, 18287.
+  17263, 17269, 17325, 17555, 18032, 18287.
 
 * A buffer overflow in gethostbyname_r and related functions performing DNS
   requests has been fixed.  If the NSS functions were called with a
index 399a3771047e8765c9f2b4ed6db308332eeb7da9..9218d4a5e3315574fa9bed3a93daaeaf8491efb5 100644 (file)
@@ -95,8 +95,11 @@ _IO_wstr_overflow (fp, c)
          wchar_t *old_buf = fp->_wide_data->_IO_buf_base;
          size_t old_wblen = _IO_wblen (fp);
          _IO_size_t new_size = 2 * old_wblen + 100;
-         if (new_size < old_wblen)
+
+         if (__glibc_unlikely (new_size < old_wblen)
+             || __glibc_unlikely (new_size > SIZE_MAX / sizeof (wchar_t)))
            return EOF;
+
          new_buf
            = (wchar_t *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (new_size
                                                                        * sizeof (wchar_t));
@@ -186,6 +189,9 @@ enlarge_userbuf (_IO_FILE *fp, _IO_off64_t offset, int reading)
     return 1;
 
   _IO_size_t newsize = offset + 100;
+  if (__glibc_unlikely (newsize > SIZE_MAX / sizeof (wchar_t)))
+    return 1;
+
   wchar_t *oldbuf = wd->_IO_buf_base;
   wchar_t *newbuf
     = (wchar_t *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (newsize