summaryrefslogtreecommitdiffstats
path: root/src
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-01-25 16:18:35 +0100
commit78eac57f3dc788345f8f3e9b6dbd3dce70b8f511 (patch)
tree18ba0ba795517f61e6de99bb0a2c8bbec1f0d77a /src
parentf172b964f6d9fc8cadeb7b5efeb3f59c0f8f16f6 (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. Fixes: QTBUG-100037 Pick-to: 6.3 6.2 5.15 5.12 Change-Id: I94600bc60f89e82a1121b418144006a683921a38 Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/sql/kernel/qsqlquery.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/sql/kernel/qsqlquery.cpp b/src/sql/kernel/qsqlquery.cpp
index 86d086c866..afa4882b1b 100644
--- a/src/sql/kernel/qsqlquery.cpp
+++ b/src/sql/kernel/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 QtSql module of the Qt Toolkit.
@@ -406,6 +406,10 @@ bool QSqlQuery::exec(const QString& query)
QElapsedTimer t;
t.start();
#endif
+ if (!driver()) {
+ qWarning("QSqlQuery::exec: called before driver has been set up");
+ return false;
+ }
if (d->ref.loadRelaxed() != 1) {
bool fo = isForwardOnly();
*this = QSqlQuery(driver()->createResult());