mirror of
https://github.com/boostorg/regex.git
synced 2025-07-17 14:22:08 +02:00
Fix bugs reported by Will Drewry: certain invalid regexes can cause the library to access invalid memory, changed to ensure that the correct exception is thrown long before this happens.
[SVN r42674]
This commit is contained in:
@ -784,6 +784,7 @@ bool basic_regex_parser<charT, traits>::parse_repeat(std::size_t low, std::size_
|
|||||||
case syntax_element_restart_continue:
|
case syntax_element_restart_continue:
|
||||||
case syntax_element_jump:
|
case syntax_element_jump:
|
||||||
case syntax_element_startmark:
|
case syntax_element_startmark:
|
||||||
|
case syntax_element_backstep:
|
||||||
// can't legally repeat any of the above:
|
// can't legally repeat any of the above:
|
||||||
fail(regex_constants::error_badrepeat, m_position - m_base);
|
fail(regex_constants::error_badrepeat, m_position - m_base);
|
||||||
return false;
|
return false;
|
||||||
@ -1869,6 +1870,7 @@ bool basic_regex_parser<charT, traits>::parse_perl_extension()
|
|||||||
if(markid == -4)
|
if(markid == -4)
|
||||||
{
|
{
|
||||||
re_syntax_base* b = this->getaddress(expected_alt_point);
|
re_syntax_base* b = this->getaddress(expected_alt_point);
|
||||||
|
// Make sure we have exactly one alternative following this state:
|
||||||
if(b->type != syntax_element_alt)
|
if(b->type != syntax_element_alt)
|
||||||
{
|
{
|
||||||
re_alt* alt = static_cast<re_alt*>(this->insert_state(expected_alt_point, syntax_element_alt, sizeof(re_alt)));
|
re_alt* alt = static_cast<re_alt*>(this->insert_state(expected_alt_point, syntax_element_alt, sizeof(re_alt)));
|
||||||
@ -1879,6 +1881,15 @@ bool basic_regex_parser<charT, traits>::parse_perl_extension()
|
|||||||
fail(regex_constants::error_bad_pattern, m_position - m_base);
|
fail(regex_constants::error_bad_pattern, m_position - m_base);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// check for invalid repetition of next state:
|
||||||
|
b = this->getaddress(expected_alt_point);
|
||||||
|
b = this->getaddress(static_cast<re_alt*>(b)->next.i, b);
|
||||||
|
if((b->type != syntax_element_assert_backref)
|
||||||
|
&& (b->type != syntax_element_startmark))
|
||||||
|
{
|
||||||
|
fail(regex_constants::error_badrepeat, m_position - m_base);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// append closing parenthesis state:
|
// append closing parenthesis state:
|
||||||
|
@ -121,6 +121,17 @@ void test_conditionals()
|
|||||||
TEST_INVALID_REGEX("(?:(a)|b)(?(?:", perl);
|
TEST_INVALID_REGEX("(?:(a)|b)(?(?:", perl);
|
||||||
TEST_INVALID_REGEX("(?:(a)|b)(?(?<", perl);
|
TEST_INVALID_REGEX("(?:(a)|b)(?(?<", perl);
|
||||||
TEST_INVALID_REGEX("(?:(a)|b)(?(?<a", perl);
|
TEST_INVALID_REGEX("(?:(a)|b)(?(?<a", perl);
|
||||||
|
|
||||||
|
TEST_INVALID_REGEX("(?(?!#?)+)", perl);
|
||||||
|
TEST_INVALID_REGEX("(?(?=:-){0})", perl);
|
||||||
|
TEST_INVALID_REGEX("(?(123){1})", perl);
|
||||||
|
TEST_INVALID_REGEX("(?(?<=A)*)", perl);
|
||||||
|
TEST_INVALID_REGEX("(?(?<=A)+)", perl);
|
||||||
|
|
||||||
|
TEST_INVALID_REGEX("(?<!*|^)", perl);
|
||||||
|
TEST_INVALID_REGEX("(?<!*|A)", perl);
|
||||||
|
TEST_INVALID_REGEX("(?<=?|A)", perl);
|
||||||
|
TEST_INVALID_REGEX("(?<=*|\B)", perl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_options()
|
void test_options()
|
||||||
|
Reference in New Issue
Block a user