summaryrefslogtreecommitdiff
path: root/ui/qt/export_pdu_dialog.cpp
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-11-29 19:29:26 +0100
committerGerald Combs <gerald@wireshark.org>2014-12-01 00:56:26 +0000
commit18f01099694ed5c2758105f893ba37589f552717 (patch)
tree78464c882944cf12058ed99ac9829ab03c69cde8 /ui/qt/export_pdu_dialog.cpp
parent846bb5394812c39359dfdbbf7e8755a7e3cf5326 (diff)
downloadwireshark-18f01099694ed5c2758105f893ba37589f552717.tar.gz
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/export_pdu_dialog.cpp')
-rw-r--r--ui/qt/export_pdu_dialog.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/ui/qt/export_pdu_dialog.cpp b/ui/qt/export_pdu_dialog.cpp
index 42506a555c..280e206f35 100644
--- a/ui/qt/export_pdu_dialog.cpp
+++ b/ui/qt/export_pdu_dialog.cpp
@@ -47,16 +47,14 @@ ExportPDUDialog::ExportPDUDialog(QWidget *parent) :
}
void ExportPDUDialog::on_buttonBox_accepted()
{
- const char *filter;
- QString tap_name;
exp_pdu_t exp_pdu_data;
exp_pdu_data.pkt_encap = wtap_wtap_encap_to_pcap_encap(WTAP_ENCAP_WIRESHARK_UPPER_PDU);
- filter = ui->displayFilterLineEdit->text().toUtf8().constData();
- tap_name = ui->comboBox->currentText();
+ const QByteArray& filter = ui->displayFilterLineEdit->text().toUtf8();
+ const QByteArray& tap_name = ui->comboBox->currentText().toUtf8();
- do_export_pdu(filter, (gchar *)tap_name.toUtf8().constData(), &exp_pdu_data);
+ do_export_pdu(filter.constData(), (gchar *)tap_name.constData(), &exp_pdu_data);
}
ExportPDUDialog::~ExportPDUDialog()
{