uisupport: Fix invalid model segfault from index
authorShane Synan <digitalcircuit36939@gmail.com>
Wed, 15 Jul 2020 23:08:41 +0000 (19:08 -0400)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 4 Oct 2020 16:18:50 +0000 (18:18 +0200)
commit47b54cd3ad35201ff2ab9ef6bfdba83fc086558d
tree3f44e609161401a0bb5561ac8275d54042988f15
parent0b277c98276e042f472e96f3eef9297a04f214f8
uisupport: Fix invalid model segfault from index

The Qt implementation of QModelIndex::child(...) automatically checks
if the QAbstractItemModel is valid, and if not, it returns an invalid
QModelIndex.  Quassel relied upon this in several places, checking if
the QModelIndex was valid without checking the QAbstractItemModel
itself, which introduced crashes upon migrating away from the
deprecated QModelIndex::child(...) function.

Specifically...

#if QT_DEPRECATED_SINCE(5, 8)
inline QModelIndex QModelIndex::child(int arow, int acolumn) const
{ return m ? m->index(arow, acolumn, *this) : QModelIndex(); }
#endif

To address this, check the QModelIndex's model to verify it's valid
wherever Quassel had previously relied upon a check to
QModelIndex::isValid() to ensure validity.  Places without a validity
check aren't adjusted under the assumption it won't ever be an issue.

Follow-up to the Qt deprecation fixes in
a453c963cf1872e14c83adf1d40a31821c166805

(It's unfortunate that Qt's deprecation warning mentioned this, but
only in the detailed documentation and not as clearly as expected:
https://doc.qt.io/qt-5/qmodelindex-obsolete.html )

Special thanks to oprypin for reporting this with a detailed,
reproducible test case!

Fixes #1583
src/client/treemodel.cpp
src/qtui/nicklistwidget.cpp
src/uisupport/abstractbuffercontainer.cpp
src/uisupport/bufferview.cpp
src/uisupport/nickviewfilter.cpp