summaryrefslogtreecommitdiff
path: root/boost/regex/v4/perl_matcher_recursive.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/regex/v4/perl_matcher_recursive.hpp')
-rw-r--r--boost/regex/v4/perl_matcher_recursive.hpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/boost/regex/v4/perl_matcher_recursive.hpp b/boost/regex/v4/perl_matcher_recursive.hpp
index 33b9158193..8eb23abfdc 100644
--- a/boost/regex/v4/perl_matcher_recursive.hpp
+++ b/boost/regex/v4/perl_matcher_recursive.hpp
@@ -900,10 +900,27 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_recursion()
{
recursion_stack.reserve(50);
}
+ //
+ // See if we've seen this recursion before at this location, if we have then
+ // we need to prevent infinite recursion:
+ //
+ for(typename std::vector<recursion_info<results_type> >::reverse_iterator i = recursion_stack.rbegin(); i != recursion_stack.rend(); ++i)
+ {
+ if(i->idx == static_cast<const re_brace*>(static_cast<const re_jump*>(pstate)->alt.p)->index)
+ {
+ if(i->location_of_start == position)
+ return false;
+ break;
+ }
+ }
+ //
+ // Now get on with it:
+ //
recursion_stack.push_back(recursion_info<results_type>());
recursion_stack.back().preturn_address = pstate->next.p;
recursion_stack.back().results = *m_presult;
recursion_stack.back().repeater_stack = next_count;
+ recursion_stack.back().location_of_start = position;
pstate = static_cast<const re_jump*>(pstate)->alt.p;
recursion_stack.back().idx = static_cast<const re_brace*>(pstate)->index;
@@ -979,6 +996,7 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_match()
recursion_stack.push_back(recursion_info<results_type>());
recursion_stack.back().preturn_address = saved_state;
recursion_stack.back().results = *m_presult;
+ recursion_stack.back().location_of_start = position;
return false;
}
return true;