Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-8752

QSqlQuery::next() may trigger an out-of-bounds array access with SQLite plugin if setForwardOnly(true) is called after QSqlQuery::exec()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P2: Important
    • 4.7.1
    • 4.6.1
    • SQL Support
    • None
    • 3e6a330d2aa6f139347fe29947721368a5186cc3

    Description

      The following code executes successfully in Qt 4.6.0 but triggers an array-out-of-bounds access in QSQLiteResultPrivate::fetchNext() in Qt 4.6.1 which I believe is caused by commit 1d6be599f5c12e9ce23bbdf081a103aa62618e15.

      Modifying the code below to call setForwardOnly(true) BEFORE QSqlQuery::exec() resolves the problem. I'm not sure if the code below is legal use of the API, though the documentation for setForwardOnly() does not mention anything in this respect.

      #include <QtCore/QCoreApplication>
      #include <QtCore/QVariant>
      #include <QtSql/QSqlDatabase>
      #include <QtSql/QSqlQuery>
      #include <QtDebug>

      int main(int argc, char** argv)
      {
      QCoreApplication app(argc,argv);

      QString connection = "test-database";
      {
      QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE",connection);
      database.setDatabaseName(":memory:");
      database.open();

      QSqlQuery createQuery(database);
      createQuery.exec("CREATE TABLE TestTable (id INTEGER PRIMARY KEY AUTOINCREMENT, content VARCHAR NOT NULL)");
      createQuery.exec("INSERT INTO TestTable VALUES(0,'FirstRow')");
      createQuery.exec("INSERT INTO TestTable VALUES(1,'SecondRow')");
      createQuery.exec("INSERT INTO TestTable VALUES(2,'ThirdRow')");

      QSqlQuery query(database);
      query.exec("SELECT content FROM TestTable");
      query.setForwardOnly(true);

      while (query.next())

      { qDebug() << query.value(0).toString(); }

      }
      QSqlDatabase::removeDatabase(connection);
      }

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            bilking Bill King
            robertknight Robert Knight
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes