]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix undefined behaviour in random dist serialization (PR93205)
authorJonathan Wakely <jwakely@redhat.com>
Wed, 26 Feb 2020 16:31:19 +0000 (16:31 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 26 Feb 2020 16:31:19 +0000 (16:31 +0000)
commita29236a23c03fe08998b81a0ef1f67e7ea185ba3
treee1a994bfab967bddc81050ce25c65f7ddc1895c2
parent7a7ef79651abd20b95d1f76479887d1ea008a62f
libstdc++: Fix undefined behaviour in random dist serialization (PR93205)

The deserialization functions for random number distributions fail to
check the stream state before using the extracted values. In some cases
this leads to using indeterminate values to resize a vector, and then
filling that vector with indeterminate values.

No values that affect control flow should be used without checking that a
good value was read from the stream.

Additionally, where reasonable to do so, defer modifying any state in
the distribution until all values have been successfully read, to avoid
modifying some of the distribution's parameters and leaving others
unchanged.

Backport from mainline
2020-01-09  Jonathan Wakely  <jwakely@redhat.com>

PR libstdc++/93205
* include/bits/random.h (operator>>): Check stream operation succeeds.
* include/bits/random.tcc: (operator>>): Likewise.
(__extract_params): New function to fill a vector from a stream.
* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error line.
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/random.h
libstdc++-v3/include/bits/random.tcc
libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc