Skip to content

Commit d6efe94

Browse files
<regex>: Limit capture groups (microsoft#4451)
1 parent 9c40b48 commit d6efe94

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

stl/inc/regex

+7-3
Original file line numberDiff line numberDiff line change
@@ -4153,9 +4153,13 @@ void _Parser<_FwdIt, _Elem, _RxTraits>::_CharacterClass() { // add bracket expre
41534153

41544154
template <class _FwdIt, class _Elem, class _RxTraits>
41554155
void _Parser<_FwdIt, _Elem, _RxTraits>::_Do_capture_group() { // add capture group
4156-
// if (_MAX_GRP <= ++_Grp_idx)
4157-
// _Error(regex_constants::error_complexity);
4158-
_Node_base* _Pos1 = _Nfa._Begin_capture_group(++_Grp_idx);
4156+
++_Grp_idx;
4157+
4158+
if (_Grp_idx >= 1000) { // hardcoded limit
4159+
_Xregex_error(regex_constants::error_stack);
4160+
}
4161+
4162+
_Node_base* _Pos1 = _Nfa._Begin_capture_group(_Grp_idx);
41594163
_Disjunction();
41604164
_Nfa._End_group(_Pos1);
41614165
_Finished_grps.resize(_Grp_idx + 1);

0 commit comments

Comments
 (0)