From b0233262b8a4ab3751cf2d94a6966a6ff56461c4 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 12 Oct 2017 21:21:52 +0800 Subject: [PATCH] Regex: Limit programs to std::numeric_limits::max() instructions --- src/regex_impl.cc | 3 +++ src/regex_impl.hh | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/regex_impl.cc b/src/regex_impl.cc index c7c6fe08..2a517d01 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -531,6 +531,9 @@ struct RegexCompiler { compile_node(m_parsed_regex.ast); push_inst(CompiledRegex::Match); + constexpr auto max_instructions = std::numeric_limits::max(); + if (m_program.instructions.size() >= max_instructions) + throw regex_error(format("regex compiled to more than {} instructions", max_instructions)); m_program.matchers = m_parsed_regex.matchers; m_program.save_count = m_parsed_regex.capture_count * 2; m_program.direction = direction; diff --git a/src/regex_impl.hh b/src/regex_impl.hh index 9a8efdd7..f1068dca 100644 --- a/src/regex_impl.hh +++ b/src/regex_impl.hh @@ -235,7 +235,7 @@ private: { Vector current_threads; Vector next_threads; - Vector processed; + Vector processed; }; enum class StepResult { Consumed, Matched, Failed };