aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-10-26 09:23:15 +0200
committerMitch Curtis <mitch.curtis@qt.io>2018-10-26 07:37:30 +0000
commit9289dfd191e2c33a64d68a9cd1c218066babf63d (patch)
tree0b15807a3c66cb97a253ee8ae91f033bac49c802
parent6dc2cb8575943f1f71c1f3c3d18500ee7c55acee (diff)
Fix heap-use-after-free in tst_QQuickDrawer
Ensure the QByteArray we set as the current test name outlives the test. Task-number: QTBUG-71387 Change-Id: Id5f75b5ffcd1a710b5d8be4796cf48ee8dd1896d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r--tests/auto/shared/qtest_quickcontrols.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/tests/auto/shared/qtest_quickcontrols.h b/tests/auto/shared/qtest_quickcontrols.h
index d1fe08f6..0ae74481 100644
--- a/tests/auto/shared/qtest_quickcontrols.h
+++ b/tests/auto/shared/qtest_quickcontrols.h
@@ -55,11 +55,15 @@ static int runTests(QObject *testObject, int argc, char *argv[])
int res = 0;
QTest::qInit(testObject, argc, argv);
const QByteArray testObjectName = QTestResult::currentTestObjectName();
+ // setCurrentTestObject() takes a C string, which means we must ensure
+ // that the string we pass in lives long enough (i.e until the next call
+ // to setCurrentTestObject()), so store the name outside of the loop.
+ QByteArray testName;
const QStringList styles = testStyles();
for (const QString &style : styles) {
qmlClearTypeRegistrations();
QQuickStyle::setStyle(style);
- const QByteArray testName = testObjectName + "::" + style.toLocal8Bit();
+ testName = testObjectName + "::" + style.toLocal8Bit();
QTestResult::setCurrentTestObject(testName);
res += QTest::qRun();
}