Skip to content

Commit

Permalink
Execute initDbSession() on DB reconnects
Browse files Browse the repository at this point in the history
Previously, the initDbSession() function would only be run on the
initial connect.  Since the initDbSession() code in PostgreSQL is
used to fix the CVE-2013-4422 SQL Injection bug, this means that
Quassel was still vulnerable to that CVE if the PostgreSQL server
is restarted or the connection is lost at any point while Quassel
is running.

This bug also causes the Qt5 psql timezone fix to stop working
after a reconnect.

The fix is to disable Qt's automatic reconnecting, check the
connection status ourselves, and reconnect if necessary, executing
the initDbSession() function afterward.
  • Loading branch information
mamarley committed Apr 23, 2015
1 parent 9e7ee3a commit 6605882
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/core/abstractsqlstorage.cpp
Expand Up @@ -53,7 +53,14 @@ QSqlDatabase AbstractSqlStorage::logDb()
if (!_connectionPool.contains(QThread::currentThread()))
addConnectionToPool();

return QSqlDatabase::database(_connectionPool[QThread::currentThread()]->name());
QSqlDatabase db = QSqlDatabase::database(_connectionPool[QThread::currentThread()]->name(),false);

if (!db.isOpen()) {
qWarning() << "Database connection" << displayName() << "for thread" << QThread::currentThread() << "was lost, attempting to reconnect...";
dbConnect(db);
}

return db;
}


Expand Down Expand Up @@ -90,6 +97,12 @@ void AbstractSqlStorage::addConnectionToPool()
db.setPassword(password());
}

dbConnect(db);
}


void AbstractSqlStorage::dbConnect(QSqlDatabase &db)
{
if (!db.open()) {
quWarning() << "Unable to open database" << displayName() << "for thread" << QThread::currentThread();
quWarning() << "-" << db.lastError().text();
Expand Down
1 change: 1 addition & 0 deletions src/core/abstractsqlstorage.h
Expand Up @@ -87,6 +87,7 @@ private slots:

private:
void addConnectionToPool();
void dbConnect(QSqlDatabase &db);

int _schemaVersion;
bool _debug;
Expand Down

0 comments on commit 6605882

Please sign in to comment.