diff options
author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-09-11 13:44:26 +0000 |
---|---|---|
committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-09-11 13:44:26 +0000 |
commit | 84bb4e67d45a8921cedd2ef64fe3cffd9ee72f44 (patch) | |
tree | bf41ef1879a653d9a02ae21f9e54237c82685b04 | |
parent | 6d8879ea4e075e4ea6c6bb1fb482d9df0918597f (diff) | |
download | gcc-kyukhin/interrupt.tar.gz |
Check read() result in std::random_device.kyukhin/interrupt
PR libstdc++/65142
* src/c++11/random.cc (random_device::_M_getval()): Check read result.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@227687 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | libstdc++-v3/ChangeLog | 5 | ||||
-rw-r--r-- | libstdc++-v3/src/c++11/random.cc | 12 |
2 files changed, 13 insertions, 4 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 42f6a54b94e..b4618effe80 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2015-09-11 Jonathan Wakely <jwakely@redhat.com> + + PR libstdc++/65142 + * src/c++11/random.cc (random_device::_M_getval()): Check read result. + 2015-09-11 John Marino <gnugcc@marino.st> Jonathan Wakely <jwakely@redhat.com> diff --git a/libstdc++-v3/src/c++11/random.cc b/libstdc++-v3/src/c++11/random.cc index edf900f6bb7..1d102c755b2 100644 --- a/libstdc++-v3/src/c++11/random.cc +++ b/libstdc++-v3/src/c++11/random.cc @@ -130,13 +130,17 @@ namespace std _GLIBCXX_VISIBILITY(default) #endif result_type __ret; + #ifdef _GLIBCXX_HAVE_UNISTD_H - read(fileno(static_cast<FILE*>(_M_file)), - static_cast<void*>(&__ret), sizeof(result_type)); + auto e = read(fileno(static_cast<FILE*>(_M_file)), + static_cast<void*>(&__ret), sizeof(result_type)); #else - std::fread(static_cast<void*>(&__ret), sizeof(result_type), - 1, static_cast<FILE*>(_M_file)); + auto e = std::fread(static_cast<void*>(&__ret), sizeof(result_type), + 1, static_cast<FILE*>(_M_file)); #endif + if (e != sizeof(result_type)) + __throw_runtime_error(__N("random_device could not read enough bytes")); + return __ret; } |