Skip to content

Commit 30dbe57

Browse files
author
Peter Hartmann
committed
QQmlComponent: Fix heap buffer overflow with bogus input
Change-Id: I8a725018a5aeb39df370f856cd77d887faa511e3 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
1 parent b63c210 commit 30dbe57

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/qml/parser/qqmljslexer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,11 @@ int Lexer::scanToken()
724724
return multilineStringLiteral ? T_MULTILINE_STRING_LITERAL : T_STRING_LITERAL;
725725
} else if (_char == QLatin1Char('\\')) {
726726
scanChar();
727+
if (_codePtr > _endPtr) {
728+
_errorCode = IllegalEscapeSequence;
729+
_errorMessage = QCoreApplication::translate("QQmlParser", "End of file reached at escape sequence");
730+
return T_ERROR;
731+
}
727732

728733
QChar u;
729734

tests/auto/qml/qqmlparser/tst_qqmlparser.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ private slots:
4949
void qmlParser_data();
5050
void qmlParser();
5151
#endif
52+
void invalidEscapeSequence();
5253

5354
private:
5455
QStringList excludedDirs;
@@ -192,6 +193,17 @@ void tst_qqmlparser::qmlParser()
192193
}
193194
#endif
194195

196+
void tst_qqmlparser::invalidEscapeSequence()
197+
{
198+
using namespace QQmlJS;
199+
200+
Engine engine;
201+
Lexer lexer(&engine);
202+
lexer.setCode(QLatin1String("\"\\"), 1);
203+
Parser parser(&engine);
204+
parser.parse();
205+
}
206+
195207
QTEST_MAIN(tst_qqmlparser)
196208

197209
#include "tst_qqmlparser.moc"

0 commit comments

Comments
 (0)