boost/backport-Disallow-repeating-a-case-change-group.patch
zhangyiru c8e96fd0cc 1.memleak
increase used_block_count when use put_mem_block
2.assertion failed
Disallow repeating a case-change group
2021-10-14 16:41:15 -04:00

43 lines
1.8 KiB
Diff

From 370afe3f446c69a7ccc4c09f056272346afc264b Mon Sep 17 00:00:00 2001
From: zhangyiru <zhangyiru3@huawei.com>
Date: Thu, 14 Oct 2021 15:55:56 -0400
Subject: [PATCH] Disallow repeating a case-change group
fix assertion failed: https://github.com/boostorg/regex/issues/151
Signed-off-by: zhangyiru <zhangyiru3@huawei.com>
---
boost/regex/v4/basic_regex_parser.hpp | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/boost/regex/v4/basic_regex_parser.hpp b/boost/regex/v4/basic_regex_parser.hpp
index 6c7065f05..2ce615943 100644
--- a/boost/regex/v4/basic_regex_parser.hpp
+++ b/boost/regex/v4/basic_regex_parser.hpp
@@ -1042,6 +1042,7 @@ bool basic_regex_parser<charT, traits>::parse_repeat(std::size_t low, std::size_
case syntax_element_jump:
case syntax_element_startmark:
case syntax_element_backstep:
+ case syntax_element_toggle_case:
// can't legally repeat any of the above:
fail(regex_constants::error_badrepeat, m_position - m_base);
return false;
@@ -3116,7 +3117,13 @@ bool basic_regex_parser<charT, traits>::unwind_alts(std::ptrdiff_t last_paren_st
m_alt_jumps.pop_back();
this->m_pdata->m_data.align();
re_jump* jmp = static_cast<re_jump*>(this->getaddress(jump_offset));
- BOOST_ASSERT(jmp->type == syntax_element_jump);
+ if (jmp->type != syntax_element_jump)
+ {
+ // Something really bad happened, this used to be an assert,
+ // but we'll make it an error just in case we should ever get here.
+ fail(regex_constants::error_unknown, this->m_position - this->m_base, "Internal logic failed while compiling the expression, probably you added a repeat to something non-repeatable!");
+ return false;
+ }
jmp->alt.i = this->m_pdata->m_data.size() - jump_offset;
}
return true;
--
2.27.0