From 597ce09c7a1d8b89e9473faae900321ef2d4181d Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 11 Oct 2018 13:33:08 +0200 Subject: JS: Limit expression and statement nesting level This is to prevent extremely deeply nested expressions and statements make the code-generator run out of (native) stack space. Task-number: QTBUG-71087 Change-Id: I8e1a20a361bff3e49101e535754546475a63ca18 Reviewed-by: Simon Hausmann --- tests/auto/qml/v4misc/tst_v4misc.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests') diff --git a/tests/auto/qml/v4misc/tst_v4misc.cpp b/tests/auto/qml/v4misc/tst_v4misc.cpp index ecc3a4100c..71f0a42907 100644 --- a/tests/auto/qml/v4misc/tst_v4misc.cpp +++ b/tests/auto/qml/v4misc/tst_v4misc.cpp @@ -43,6 +43,8 @@ private slots: void subClassing_data(); void subClassing(); + + void nestingDepth(); }; void tst_v4misc::tdzOptimizations_data() @@ -173,6 +175,28 @@ void tst_v4misc::subClassing() QVERIFY(!result.isError()); } +void tst_v4misc::nestingDepth() +{ + { // left recursive + QString s(40000, '`'); + + QJSEngine engine; + QJSValue result = engine.evaluate(s); + QVERIFY(result.isError()); + QCOMPARE(result.toString(), "SyntaxError: Maximum statement or expression depth exceeded"); + } + + { // right recursive + QString s(200000, '-'); + s += "\nd"; + + QJSEngine engine; + QJSValue result = engine.evaluate(s); + QVERIFY(result.isError()); + QCOMPARE(result.toString(), "SyntaxError: Maximum statement or expression depth exceeded"); + } +} + QTEST_MAIN(tst_v4misc); #include "tst_v4misc.moc" -- cgit v1.2.3