Fix buffer over-run error when parsing invalid regex.

See: https://svn.boost.org/trac/boost/ticket/12222.
This commit is contained in:
jzmaddock
2016-06-09 19:00:29 +01:00
parent e3228b61eb
commit 7719dedbaf
2 changed files with 6 additions and 1 deletions

View File

@ -543,7 +543,11 @@ bool basic_regex_parser<charT, traits>::parse_open_paren()
template <class charT, class traits> template <class charT, class traits>
bool basic_regex_parser<charT, traits>::parse_basic_escape() bool basic_regex_parser<charT, traits>::parse_basic_escape()
{ {
++m_position; if(++m_position == m_end)
{
fail(regex_constants::error_paren, m_position - m_base);
return false;
}
bool result = true; bool result = true;
switch(this->m_traits.escape_syntax_type(*m_position)) switch(this->m_traits.escape_syntax_type(*m_position))
{ {

View File

@ -61,6 +61,7 @@ void basic_tests()
TEST_REGEX_SEARCH("\\(\\)", basic, "", match_default, make_array(0, 0, 0, 0, -2, -2)); TEST_REGEX_SEARCH("\\(\\)", basic, "", match_default, make_array(0, 0, 0, 0, -2, -2));
TEST_INVALID_REGEX("\\(", basic); TEST_INVALID_REGEX("\\(", basic);
TEST_INVALID_REGEX("\\)", basic); TEST_INVALID_REGEX("\\)", basic);
TEST_INVALID_REGEX("\\", basic);
TEST_INVALID_REGEX("\\(aa", basic); TEST_INVALID_REGEX("\\(aa", basic);
TEST_INVALID_REGEX("aa\\)", basic); TEST_INVALID_REGEX("aa\\)", basic);
TEST_REGEX_SEARCH("()", basic, "()", match_default, make_array(0, 2, -2, -2)); TEST_REGEX_SEARCH("()", basic, "()", match_default, make_array(0, 2, -2, -2));