From 9753bcd0ad4aa8b01f25368251b46976807d4a48 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 11 Oct 2017 19:28:22 +0800 Subject: [PATCH] Regex: limit explicit quantifiers value (too 1000 for now) Fixes #1628 --- src/regex_impl.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/regex_impl.cc b/src/regex_impl.cc index 11d0429a..48b69ea2 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -418,7 +418,8 @@ private: if (at_end()) return {ParsedRegex::Quantifier::One}; - auto read_int = [](auto& pos, auto begin, auto end) { + constexpr int max_repeat = 1000; + auto read_int = [max_repeat, this](auto& pos, auto begin, auto end) { int res = 0; for (; pos != end; ++pos) { @@ -426,6 +427,8 @@ private: if (cp < '0' or cp > '9') return pos == begin ? -1 : res; res = res * 10 + cp - '0'; + if (res > max_repeat) + parse_error(format("Explicit quantifier is too big, maximum is {}", max_repeat)); } return res; };