]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix unsafe comma operators in <random> [PR122062]
authorJonathan Wakely <jwakely@redhat.com>
Thu, 25 Sep 2025 16:23:28 +0000 (17:23 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 26 Sep 2025 10:01:08 +0000 (11:01 +0100)
commit11ce485bcffac0db005d77e100420535e54d0aa5
tree0fc2292d59c7a82243b646578558e05023b9d4d4
parent947b22d9d0622f4a1bf7476f76f17b0d48201c4e
libstdc++: Fix unsafe comma operators in <random> [PR122062]

This fixes a 'for' loop in std::piecewise_linear_distribution that
increments two iterators with a comma operator between them, making it
vulnerable to evil overloads of the comma operator.

It also changes a 'for' loop used by some other distributions, even
though those are only used with std::vector<double>::iterator and so
won't find any overloaded commas.

libstdc++-v3/ChangeLog:

PR libstdc++/122062
* include/bits/random.tcc (__detail::__normalize): Use void cast
for operands of comma operator.
(piecewise_linear_distribution): Likewise.
* testsuite/26_numerics/random/piecewise_linear_distribution/cons/122062.cc:
New test.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
Reviewed-by: Hewill Kang <hewillk@gmail.com>
libstdc++-v3/include/bits/random.tcc
libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/122062.cc [new file with mode: 0644]