summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2022-01-24 12:44:38 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2022-02-28 12:36:49 +0100
commitba926780d1ba41fa64b32b9a01e4b070956fb75f (patch)
treef0fc2931f4a251db1544640ff70fd7132d8af425 /tests
parent21ed51d47165899021db4538dcf5301cc707cdb4 (diff)
Check for null driver() before trying to exec()
QSqlQuery::exec() took for granted that it can dereference driver(), which should be true for all sane usage; however, it should not crash if used misguidedly. Added regression test, based on bug report's reproducer, which crashes without the fix. Includes the fix to the test, moving it to the end of tst_qsqlquwry. It leaves the system in a state that breaks at least one later test, so put it last. This issue only showed upon picking back from dev, but has since been seen on dev. Fixes: QTBUG-100037 Change-Id: I94600bc60f89e82a1121b418144006a683921a38 Reviewed-by: Andy Shaw <andy.shaw@qt.io> (cherry picked from commit 78eac57f3dc788345f8f3e9b6dbd3dce70b8f511) Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
index cbc2cc2c1b..85c21dd15c 100644
--- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -269,6 +269,10 @@ private slots:
void ibaseArray_data() { generic_data("QIBASE"); }
void ibaseArray();
+ // Double addDatabase() with same name leaves system in a state that breaks
+ // invalidQuery() if run later; so put this one last !
+ void prematureExec_data() { generic_data(); }
+ void prematureExec();
private:
// returns all database connections
void generic_data(const QString &engine=QString());
@@ -2878,6 +2882,35 @@ void tst_QSqlQuery::execErrorRecovery()
QVERIFY_SQL( q, exec() );
}
+void tst_QSqlQuery::prematureExec()
+{
+ QFETCH(QString, dbName);
+ // We only want the engine name, for addDatabase():
+ int cut = dbName.indexOf(QChar('@'));
+ if (cut < 0)
+ QSKIP("Failed to parse database type out of name");
+ dbName.truncate(cut);
+ cut = dbName.indexOf(QChar('_'));
+ if (cut >= 0)
+ dbName = dbName.sliced(cut + 1);
+
+ auto db = QSqlDatabase::addDatabase(dbName);
+ QSqlQuery q(db);
+
+ QTest::ignoreMessage(QtWarningMsg,
+ "QSqlDatabasePrivate::removeDatabase: connection "
+ "'qt_sql_default_connection' is still in use, all "
+ "queries will cease to work.");
+ QTest::ignoreMessage(QtWarningMsg,
+ "QSqlDatabasePrivate::addDatabase: duplicate connection name "
+ "'qt_sql_default_connection', old connection removed.");
+ auto otherDb = QSqlDatabase::addDatabase(dbName);
+
+ QTest::ignoreMessage(QtWarningMsg, "QSqlQuery::exec: called before driver has been set up");
+ // QTBUG-100037: shouldn't crash !
+ QVERIFY(!q.exec("select stuff from TheVoid"));
+}
+
void tst_QSqlQuery::lastInsertId()
{
QFETCH( QString, dbName );