libstdc++: Check for overflow in regex back-reference [PR106607]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 22 Aug 2022 14:16:16 +0000 (15:16 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 22 Aug 2022 21:52:24 +0000 (22:52 +0100)
commit1b09eea33f2bf9d1eae73b25cc25efb05ea1dc3f
tree13ab4879e18170f3920e84ce931e44a006f38e84
parent990124c35cd60cd23e0b70fc84cfb75311e80276
libstdc++: Check for overflow in regex back-reference [PR106607]

Currently we fail to notice integer overflow when parsing a
back-reference expression, or when converting the parsed result from
long to int. This changes the result to be int, so no conversion is
needed, and uses the overflow-checking built-ins to detect an
out-of-range back-reference.

libstdc++-v3/ChangeLog:

PR libstdc++/106607
* include/bits/regex_compiler.tcc (_Compiler::_M_cur_int_value):
Use built-ins to check for integer overflow in back-reference
number.
* testsuite/28_regex/basic_regex/106607.cc: New test.
libstdc++-v3/include/bits/regex_compiler.tcc
libstdc++-v3/testsuite/28_regex/basic_regex/106607.cc [new file with mode: 0644]