Cherrypick Text Handler Avoid accessing QString out of bounds to 23.04

Add end state to text handler and use to ensure that in nextTokenType to stop an out of bounds access to m_databuffer


(cherry picked from commit 0d6a83b063)
This commit is contained in:
James Graham
2023-03-16 17:32:58 +00:00
committed by Tobias Fella
parent d3f0902835
commit ecd7a5edff
2 changed files with 7 additions and 2 deletions

View File

@@ -219,8 +219,12 @@ void TextHandler::next()
void TextHandler::nextTokenType()
{
if (m_nextTokenType == Type::Tag && getTagType() == QStringLiteral("code") && !isCloseTag()
&& m_dataBuffer.indexOf(QStringLiteral("</code>"), m_pos) != m_pos) {
if (m_pos >= m_dataBuffer.length()) {
// This is to stop the function accessing an index outside the length of
// m_dataBuffer during the final loop.
m_nextTokenType = Type::End;
} else if (m_nextTokenType == Type::Tag && getTagType() == QStringLiteral("code") && !isCloseTag()
&& m_dataBuffer.indexOf(QStringLiteral("</code>"), m_pos) != m_pos) {
m_nextTokenType = Type::TextCode;
} else if (m_dataBuffer[m_pos] == u'<' && m_dataBuffer[m_pos + 1] != u' ') {
m_nextTokenType = Type::Tag;