From e4e87a2ece1e0c9901514fea094f31863b64b570 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 7 Mar 2018 15:12:13 +0100 Subject: sqlite: Prevent a crash when sqlite does not detect any parameters When using a virtual table inside a SQLite database it is possible that it does not report the right number of parameters. Therefore we need to account for this case to prevent it from crashing when trying to bind parameters it thinks does not exist. Task-number: QTBUG-66816 Change-Id: I3ff70bb1fe73091f43c3df53616f75858e451cfd Reviewed-by: Jarek Kobus Reviewed-by: Edward Welbourne --- src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/plugins/sqldrivers/sqlite') diff --git a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp index d1a6582c5a..f715d3cba3 100644 --- a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp +++ b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp @@ -467,7 +467,10 @@ bool QSQLiteResult::exec() #if (SQLITE_VERSION_NUMBER >= 3003011) // In the case of the reuse of a named placeholder - if (paramCount < values.count()) { + // We need to check explicitly that paramCount is greater than 1, as sqlite + // can end up in a case where for virtual tables it returns 0 even though it + // has parameters + if (paramCount > 1 && paramCount < values.count()) { const auto countIndexes = [](int counter, const QList& indexList) { return counter + indexList.length(); }; -- cgit v1.2.3