1From bdf1ff052a8e23d637f2c838fa5642d78fcedc33 Mon Sep 17 00:00:00 2001
2From: Paul Pluzhnikov <ppluzhnikov@google.com>
3Date: Sun, 22 Feb 2015 12:01:47 -0800
4Subject: [PATCH] Fix BZ #17269 -- _IO_wstr_overflow integer overflow
5
6---
7 ChangeLog | 6 ++++++
8 NEWS | 6 +++---
9 libio/wstrops.c | 8 +++++++-
10 3 files changed, 16 insertions(+), 4 deletions(-)
11
12diff --git a/libio/wstrops.c b/libio/wstrops.c
13index 43d847d..3993579 100644
14--- a/libio/wstrops.c
15+++ b/libio/wstrops.c
16@@ -95,8 +95,11 @@ _IO_wstr_overflow (fp, c)
17 wchar_t *old_buf = fp->_wide_data->_IO_buf_base;
18 size_t old_wblen = _IO_wblen (fp);
19 _IO_size_t new_size = 2 * old_wblen + 100;
20- if (new_size < old_wblen)
21+
22+ if (__glibc_unlikely (new_size < old_wblen)
23+ || __glibc_unlikely (new_size > SIZE_MAX / sizeof (wchar_t)))
24 return EOF;
25+
26 new_buf
27 = (wchar_t *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (new_size
28 * sizeof (wchar_t));
29@@ -186,6 +189,9 @@ enlarge_userbuf (_IO_FILE *fp, _IO_off64_t offset, int reading)
30 return 1;
31
32 _IO_size_t newsize = offset + 100;
33+ if (__glibc_unlikely (newsize > SIZE_MAX / sizeof (wchar_t)))
34+ return 1;
35+
36 wchar_t *oldbuf = wd->_IO_buf_base;
37 wchar_t *newbuf
38 = (wchar_t *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (newsize
39