diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-02-15 14:04:54 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-02-18 07:24:08 +0000 |
commit | 885e4af1f4ba3f047c3d932a1a780ddbba481170 (patch) | |
tree | 0ff818ac338c3fbe400fb5380c14c074ca8553b8 | |
parent | 94d30df911dccd830a18d7c2e75397505ef9a600 (diff) |
QML: Don't crash the parser on certain kinds of bad input
Fixes: QTBUG-72734
Change-Id: I92146ec517c6a26a67e13830618e137f2a3021c2
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r-- | src/qml/parser/qqmljs.g | 8 | ||||
-rw-r--r-- | tests/auto/qml/qqmlparser/tst_qqmlparser.cpp | 10 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g index 860a4e999e..b86dba6daa 100644 --- a/src/qml/parser/qqmljs.g +++ b/src/qml/parser/qqmljs.g @@ -3963,8 +3963,12 @@ ClassElementList: ClassElement; ClassElementList: ClassElementList ClassElement; /. case $rule_number: { - if (sym(2).Node) - sym(1).ClassElementList = sym(1).ClassElementList->append(sym(2).ClassElementList); + if (sym(1).Node) { + if (sym(2).Node) + sym(1).ClassElementList = sym(1).ClassElementList->append(sym(2).ClassElementList); + } else if (sym(2).Node) { + sym(1).Node = sym(2).Node; + } } break; ./ diff --git a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp index ce9d0ac894..c2c73935c0 100644 --- a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp +++ b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp @@ -53,6 +53,7 @@ private slots: void stringLiteral(); void noSubstitutionTemplateLiteral(); void templateLiteral(); + void leadingSemicolonInClass(); private: QStringList excludedDirs; @@ -274,6 +275,15 @@ void tst_qqmlparser::templateLiteral() QVERIFY(e); } +void tst_qqmlparser::leadingSemicolonInClass() +{ + QQmlJS::Engine engine; + QQmlJS::Lexer lexer(&engine); + lexer.setCode(QLatin1String("class X{;n(){}}"), 1); + QQmlJS::Parser parser(&engine); + QVERIFY(parser.parseProgram()); +} + QTEST_MAIN(tst_qqmlparser) #include "tst_qqmlparser.moc" |