diff options
author | Matthew Vogt <matthew.vogt@nokia.com> | 2012-07-06 09:53:03 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-09 04:01:19 +0200 |
commit | 19c0a31319148d4ac716f7cb3295891b5a3b20d9 (patch) | |
tree | ec01ac1d68d4888c58a4f3b4f547a287a4c7491d /tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp | |
parent | 49a3883e86b61d8facfeea9c43037d484cb50b92 (diff) |
Do not permit excessive recursion in component creation
Limit recursion during component creation to prevent infinite
recursion resulting in a crash. Recursion results from invoking
createObject() in the Component.onCompleted handler.
Task-number: QTBUG-25439
Change-Id: Ica2ba099d82b5747c938501af04e67f7ace8402e
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp')
-rw-r--r-- | tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp index be38829f65..3a3952d101 100644 --- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp +++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp @@ -114,6 +114,8 @@ private slots: void componentUrlCanonicalization(); void onDestructionLookup(); void onDestructionCount(); + void recursion(); + void recursionContinuation(); private: QQmlEngine engine; @@ -410,6 +412,34 @@ void tst_qqmlcomponent::onDestructionCount() QCOMPARE(warnings.count(), 0); } +void tst_qqmlcomponent::recursion() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("recursion.qml")); + + QTest::ignoreMessage(QtWarningMsg, QLatin1String("QQmlComponent: Component creation is recursing - aborting").data()); + QScopedPointer<QObject> object(component.create()); + QVERIFY(object != 0); + + // Sub-object creation does not succeed + QCOMPARE(object->property("success").toBool(), false); +} + +void tst_qqmlcomponent::recursionContinuation() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("recursionContinuation.qml")); + + for (int i = 0; i < 10; ++i) + QTest::ignoreMessage(QtWarningMsg, QLatin1String("QQmlComponent: Component creation is recursing - aborting").data()); + + QScopedPointer<QObject> object(component.create()); + QVERIFY(object != 0); + + // Eventual sub-object creation succeeds + QVERIFY(object->property("success").toBool()); +} + QTEST_MAIN(tst_qqmlcomponent) #include "tst_qqmlcomponent.moc" |