mirror of
https://github.com/boostorg/regex.git
synced 2025-07-23 09:07:25 +02:00
Regex: Repeating a repeat is not allowed, even if there is a comment block in between the two.
Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3479#c2
This commit is contained in:
@ -1077,21 +1077,40 @@ bool basic_regex_parser<charT, traits>::parse_repeat(std::size_t low, std::size_
|
|||||||
// Check for illegal following quantifier, we have to do this here, because
|
// Check for illegal following quantifier, we have to do this here, because
|
||||||
// the extra states we insert below circumvents our usual error checking :-(
|
// the extra states we insert below circumvents our usual error checking :-(
|
||||||
//
|
//
|
||||||
if ((this->flags() & (regbase::main_option_type | regbase::mod_x | regbase::no_perl_ex)) == regbase::mod_x)
|
bool contin = false;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
// whitespace skip:
|
if ((this->flags() & (regbase::main_option_type | regbase::mod_x | regbase::no_perl_ex)) == regbase::mod_x)
|
||||||
while ((m_position != m_end) && this->m_traits.isctype(*m_position, this->m_mask_space))
|
{
|
||||||
++m_position;
|
// whitespace skip:
|
||||||
}
|
while ((m_position != m_end) && this->m_traits.isctype(*m_position, this->m_mask_space))
|
||||||
switch(this->m_traits.syntax_type(*m_position))
|
++m_position;
|
||||||
{
|
}
|
||||||
case regex_constants::syntax_star:
|
if (m_position != m_end)
|
||||||
case regex_constants::syntax_plus:
|
{
|
||||||
case regex_constants::syntax_question:
|
switch (this->m_traits.syntax_type(*m_position))
|
||||||
case regex_constants::syntax_open_brace:
|
{
|
||||||
fail(regex_constants::error_badrepeat, m_position - m_base);
|
case regex_constants::syntax_star:
|
||||||
return false;
|
case regex_constants::syntax_plus:
|
||||||
}
|
case regex_constants::syntax_question:
|
||||||
|
case regex_constants::syntax_open_brace:
|
||||||
|
fail(regex_constants::error_badrepeat, m_position - m_base);
|
||||||
|
return false;
|
||||||
|
case regex_constants::syntax_open_mark:
|
||||||
|
// Do we have a comment? If so we need to skip it here...
|
||||||
|
if ((m_position + 2 < m_end) && this->m_traits.syntax_type(*(m_position + 1)) == regex_constants::syntax_question
|
||||||
|
&& this->m_traits.syntax_type(*(m_position + 2)) == regex_constants::syntax_hash)
|
||||||
|
{
|
||||||
|
while ((m_position != m_end)
|
||||||
|
&& (this->m_traits.syntax_type(*m_position++) != regex_constants::syntax_close_mark)) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
contin = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
contin = false;
|
||||||
|
} while (contin);
|
||||||
}
|
}
|
||||||
re_brace* pb = static_cast<re_brace*>(this->insert_state(insert_point, syntax_element_startmark, sizeof(re_brace)));
|
re_brace* pb = static_cast<re_brace*>(this->insert_state(insert_point, syntax_element_startmark, sizeof(re_brace)));
|
||||||
pb->index = -3;
|
pb->index = -3;
|
||||||
@ -2010,7 +2029,7 @@ bool basic_regex_parser<charT, traits>::parse_perl_extension()
|
|||||||
{
|
{
|
||||||
while((m_position != m_end)
|
while((m_position != m_end)
|
||||||
&& (this->m_traits.syntax_type(*m_position++) != regex_constants::syntax_close_mark))
|
&& (this->m_traits.syntax_type(*m_position++) != regex_constants::syntax_close_mark))
|
||||||
{}
|
{}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
@ -205,6 +205,11 @@ void test_options()
|
|||||||
TEST_REGEX_SEARCH("(a (?x)b c)d e", perl, "a bcde", match_default, make_array(-2, -2));
|
TEST_REGEX_SEARCH("(a (?x)b c)d e", perl, "a bcde", match_default, make_array(-2, -2));
|
||||||
TEST_REGEX_SEARCH("(a b(?x)c d (?-x)e f)", perl, "a bcde f", match_default, make_array(0, 8, 0, 8, -2, -2));
|
TEST_REGEX_SEARCH("(a b(?x)c d (?-x)e f)", perl, "a bcde f", match_default, make_array(0, 8, 0, 8, -2, -2));
|
||||||
TEST_REGEX_SEARCH("(a b(?x)c d (?-x)e f)", perl, "abcdef", match_default, make_array(-2, -2));
|
TEST_REGEX_SEARCH("(a b(?x)c d (?-x)e f)", perl, "abcdef", match_default, make_array(-2, -2));
|
||||||
|
|
||||||
|
TEST_INVALID_REGEX("a++(?#abc)+", perl);
|
||||||
|
TEST_INVALID_REGEX("a++(?#abc)?", perl);
|
||||||
|
TEST_INVALID_REGEX("a++(?#abc)*", perl);
|
||||||
|
TEST_INVALID_REGEX("a++(?#abc){2}", perl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_options2()
|
void test_options2()
|
||||||
|
Reference in New Issue
Block a user