Fix incorrect use of subject end/begin in regex execution
This could lead to reading past subject string end in certain conditions Fixes #4794
This commit is contained in:
parent
a02bd19533
commit
f5d5274c5f
|
@ -220,6 +220,7 @@ private:
|
|||
m_results.values().clear();
|
||||
std::move(m_vm.captures().begin(), m_vm.captures().end(), std::back_inserter(m_results.values()));
|
||||
m_next_pos = forward ? m_results[0].second : m_results[0].first;
|
||||
kak_assert(forward ? (m_next_pos <= m_end) : (m_next_pos >= m_begin));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1204,6 +1204,8 @@ struct TestVM : CompiledRegex, ThreadedRegexVM<const char*, mode>
|
|||
{
|
||||
return TestVM::ThreadedRegexVM::exec(re.begin(), re.end(), re.begin(), re.end(), flags);
|
||||
}
|
||||
|
||||
using TestVM::ThreadedRegexVM::exec;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1564,6 +1566,12 @@ auto test_regex = UnitTest{[]{
|
|||
kak_assert(vm.exec("д", RegexExecFlags::None));
|
||||
}
|
||||
|
||||
{
|
||||
TestVM<RegexMode::Forward | RegexMode::Search> vm{"ab"};
|
||||
const char str[] = "fa😄ab";
|
||||
kak_assert(not vm.exec(str, str+4, str, str + sizeof(str)-1, RegexExecFlags::None));
|
||||
}
|
||||
|
||||
{
|
||||
TestVM<> vm{R"(\0\x0A\u00260e\u00260F)"};
|
||||
const char str[] = "\0\n☎☏"; // work around the null byte in the literal
|
||||
|
|
|
@ -492,8 +492,8 @@ private:
|
|||
return m_found_match;
|
||||
}
|
||||
|
||||
forward ? utf8::to_next(pos, config.subject_end)
|
||||
: utf8::to_previous(pos, config.subject_begin);
|
||||
forward ? utf8::to_next(pos, config.end)
|
||||
: utf8::to_previous(pos, config.end);
|
||||
|
||||
if (search and not m_found_match)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user