]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Avoid overflow in istream::get(streambuf&) [LWG 3464]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 20 Jul 2020 19:06:46 +0000 (20:06 +0100)
committerGiuliano Belinassi <giuliano.belinassi@usp.br>
Mon, 17 Aug 2020 16:18:37 +0000 (13:18 -0300)
commit76bc35dced1f6b0d4c1774e8cd0e23724d6d9a40
tree85d820e539abbbb68d626b42ecc3822a1745e5c6
parente09313ee673a7a23f59e2d34982f707c69a50ac0
libstdc++: Avoid overflow in istream::get(streambuf&) [LWG 3464]

Similar to the recent changes to basic_istream::ignore, this change
ensures that _M_gcount doesn't overflow when extracting characters and
inserting them into another streambuf.

The solution used here is to use unsigned long long for the count. We
assume that the number of characters extracted won't exceed the maximum
value for that type, but even if it does we avoid any undefined
behaviour.

libstdc++-v3/ChangeLog:

* include/bits/istream.tcc
(basic_istream::get(__streambuf_type&, char_type): Use unsigned
long long for counter and check if it would overflow _M_gcount.
* testsuite/27_io/basic_istream/get/char/lwg3464.cc: New test.
* testsuite/27_io/basic_istream/get/wchar_t/lwg3464.cc: New test.
libstdc++-v3/include/bits/istream.tcc
libstdc++-v3/testsuite/27_io/basic_istream/get/char/lwg3464.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_istream/get/wchar_t/lwg3464.cc [new file with mode: 0644]