summaryrefslogtreecommitdiffstats
path: root/libcxx/include/regex
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2017-09-12 17:56:59 +0000
committerMarshall Clow <mclow.lists@gmail.com>2017-09-12 17:56:59 +0000
commit5a72679338f9dc0e38c98befe65aac73de1822ab (patch)
treef557c6358713889624e6c472e8d04cfac5ba62de /libcxx/include/regex
parent06ff655e591bc8cf2bcdc0358c49f8872b0f3a0e (diff)
downloadbcm5719-llvm-5a72679338f9dc0e38c98befe65aac73de1822ab.tar.gz
bcm5719-llvm-5a72679338f9dc0e38c98befe65aac73de1822ab.zip
Apply D28224: 'Throw exception after too many steps' Fixes PR#20291. Thanks to Tim Shen for the patch
llvm-svn: 313056
Diffstat (limited to 'libcxx/include/regex')
-rw-r--r--libcxx/include/regex20
1 files changed, 20 insertions, 0 deletions
diff --git a/libcxx/include/regex b/libcxx/include/regex
index 77ca648109b..dfc97c58a3f 100644
--- a/libcxx/include/regex
+++ b/libcxx/include/regex
@@ -773,6 +773,8 @@ _LIBCPP_PUSH_MACROS
#include <__undef_macros>
+#define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096
+
_LIBCPP_BEGIN_NAMESPACE_STD
namespace regex_constants
@@ -5552,8 +5554,14 @@ basic_regex<_CharT, _Traits>::__match_at_start_ecma(
__states.back().__node_ = __st;
__states.back().__flags_ = __flags;
__states.back().__at_first_ = __at_first;
+ int __counter = 0;
+ int __length = __last - __first;
do
{
+ ++__counter;
+ if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
+ __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
+ __throw_regex_error<regex_constants::error_complexity>();
__state& __s = __states.back();
if (__s.__node_)
__s.__node_->__exec(__s);
@@ -5627,8 +5635,14 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
__states.back().__flags_ = __flags;
__states.back().__at_first_ = __at_first;
bool __matched = false;
+ int __counter = 0;
+ int __length = __last - __first;
do
{
+ ++__counter;
+ if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
+ __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
+ __throw_regex_error<regex_constants::error_complexity>();
__state& __s = __states.back();
if (__s.__node_)
__s.__node_->__exec(__s);
@@ -5724,8 +5738,14 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
__states.back().__at_first_ = __at_first;
const _CharT* __current = __first;
bool __matched = false;
+ int __counter = 0;
+ int __length = __last - __first;
do
{
+ ++__counter;
+ if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
+ __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
+ __throw_regex_error<regex_constants::error_complexity>();
__state& __s = __states.back();
if (__s.__node_)
__s.__node_->__exec(__s);
OpenPOWER on IntegriCloud