mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibRegex: Add bounds check to Lexer::back()
If the offset is zero and we're already at the end of the lexer's input an out of bounds read (m_source[m_position]) would occur. Also check that the offset is not more than m_position (which should never be the case, and would result in m_position underflowing). Fixes #4253.
This commit is contained in:
parent
7094697743
commit
8284f87867
Notes:
sideshowbarker
2024-07-19 01:10:09 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/8284f878673 Pull-request: https://github.com/SerenityOS/serenity/pull/4256 Issue: https://github.com/SerenityOS/serenity/issues/4253
1 changed files with 4 additions and 1 deletions
|
@ -64,8 +64,11 @@ ALWAYS_INLINE char Lexer::peek(size_t offset) const
|
|||
|
||||
void Lexer::back(size_t offset)
|
||||
{
|
||||
ASSERT(offset <= m_position);
|
||||
if (!offset)
|
||||
return;
|
||||
m_position -= offset;
|
||||
m_previous_position = m_position - 1;
|
||||
m_previous_position = (m_position > 0) ? m_position - 1 : 0;
|
||||
m_current_char = m_source[m_position];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue