Review Request 128277: Fix unsafe KDirModelDirNode* casts

Rob Wu rob at robwu.nl
Thu Jun 23 16:55:49 UTC 2016


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://git.reviewboard.kde.org/r/128277/
-----------------------------------------------------------

Review request for KDE Frameworks.


Repository: kio


Description
-------

Replace two isDir debug assertions with conditionals, because
there is no guarantee that the parameter is a directory.


Diffs
-----

  autotests/kdirmodeltest.cpp 1a14a01 
  src/widgets/kdirmodel.cpp eab0121 

Diff: https://git.reviewboard.kde.org/r/128277/diff/


Testing
-------

To test, I first configured ASAN by passing the following to cmake:
`-DCMAKE_CXX_FLAGS="-fsanitize=address -fsanitize=undefined"`

KDirModel::index was tested as follows:

```
make kdirmodeltest
ASAN_OPTIONS=detect_leaks=0 ./autotests/kdirmodeltest testIndex
```

KDirModel::fetchMore is tested as follows (manually):

1. Create `a.out` as follows:

```c++
// g++ `pkg-config --cflags --libs Qt5Widgets` main.cpp -fPIC -fsanitize=address
#include <QApplication>
#include <QFileDialog>
#include <QTemporaryDir>

int main(int argc, char **argv) {
    QTemporaryDir tempDir;
    QFile(tempDir.path() + "/filename.tex").open(QIODevice::WriteOnly);

    QApplication app(argc, argv);
    QStringList filesNames = QFileDialog::getOpenFileNames(
            Q_NULLPTR, "Open File", tempDir.path(), "TeX files (*.tex)");

    return app.exec();
}
```
2. Run it. In the file dialog, type "./".
3. A dropdown shows the files in the directory ("filename.tex").
4. Press arrow down. Now the filename will be matched and NOTHING should happen.

Before this patch, step 4 would crash; This is a reduced test case based on
a crash when I tried to save my work in TexMaker's (Save As dialog).


Thanks,

Rob Wu

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20160623/1e646452/attachment.html>


More information about the Kde-frameworks-devel mailing list