diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-11-29 19:29:26 +0100 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2014-12-01 00:56:26 +0000 |
commit | 18f01099694ed5c2758105f893ba37589f552717 (patch) | |
tree | 78464c882944cf12058ed99ac9829ab03c69cde8 /ui/qt/display_filter_combo.cpp | |
parent | 846bb5394812c39359dfdbbf7e8755a7e3cf5326 (diff) |
qt: fix use-after-free pattern
qstring.toUtf8() returns a QByteArray object and .constData() returns
a pointer inside that object. It is not safe to store this pointer as
it will become invalid after the statement. Store a const reference
instead. (Due to scoping differences, some are copy-assigned though.)
In the UAT dialog, strlen(bytes.constData()) has also been replaced by
bytes.size() as an optimization.
Caught by ASAN.
Change-Id: Ie09f999a32d0ef1abaa1e658b9403b74bedffc37
Reviewed-on: https://code.wireshark.org/review/5528
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui/qt/display_filter_combo.cpp')
-rw-r--r-- | ui/qt/display_filter_combo.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/ui/qt/display_filter_combo.cpp b/ui/qt/display_filter_combo.cpp index 576a9a9b2e..edcad297fa 100644 --- a/ui/qt/display_filter_combo.cpp +++ b/ui/qt/display_filter_combo.cpp @@ -90,12 +90,11 @@ extern "C" void dfilter_recent_combo_write_all(FILE *rf) { void DisplayFilterCombo::writeRecent(FILE *rf) { int i; - const char *filter_str; for (i = 0; i < count(); i++) { - filter_str = itemText(i).toUtf8().constData(); - if(filter_str && strlen(filter_str) > 0) { - fprintf(rf, RECENT_KEY_DISPLAY_FILTER ": %s\n", filter_str); + const QByteArray& filter = itemText(i).toUtf8(); + if (!filter.isEmpty()) { + fprintf(rf, RECENT_KEY_DISPLAY_FILTER ": %s\n", filter.constData()); } } } |