From 2c6c0be0c1d2335091fb46f52c3c816cf1250820 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 16 Oct 2017 19:36:06 +0800 Subject: [PATCH] Regex: abort compilation as soon as we hit the instruction count limit --- src/regex_impl.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/regex_impl.cc b/src/regex_impl.cc index e3b73df1..232bb865 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -579,9 +579,6 @@ 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; @@ -756,7 +753,10 @@ private: uint32_t push_inst(CompiledRegex::Op op, uint32_t param = 0) { + constexpr auto max_instructions = std::numeric_limits::max(); uint32_t res = m_program.instructions.size(); + if (res > max_instructions) + throw regex_error(format("regex compiled to more than {} instructions", max_instructions)); m_program.instructions.push_back({ op, false, 0, param }); return res; }