aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Knall <rknall@gmail.com>2022-02-11 18:51:54 +0000
committerA Wireshark GitLab Utility <6629907-ws-gitlab-utility@users.noreply.gitlab.com>2022-02-11 18:51:54 +0000
commit699c3c051ae100e8cf9ab8477ec3ce2459a9b984 (patch)
tree7dabc42bff07c7fbfcbdb4254b7af73e7827094c
parent52955b9c43a99942b332a8a2c0c2995608a539a1 (diff)
Qt: Fix ASAN heap-use-after-free
-rw-r--r--ui/qt/manage_interfaces_dialog.cpp62
-rw-r--r--ui/qt/manage_interfaces_dialog.h2
2 files changed, 13 insertions, 51 deletions
diff --git a/ui/qt/manage_interfaces_dialog.cpp b/ui/qt/manage_interfaces_dialog.cpp
index ea1e762d79..bf4905d1a1 100644
--- a/ui/qt/manage_interfaces_dialog.cpp
+++ b/ui/qt/manage_interfaces_dialog.cpp
@@ -559,67 +559,31 @@ void ManageInterfacesDialog::on_addRemote_clicked()
dlg->show();
}
-int ManageInterfacesDialog::remoteInterfacesExists(char* device_name){
- int exists = 0;
- QTreeWidgetItemIterator it(ui->remoteList);
-
- while (*it) {
- QTreeWidgetItem * item = *it;
-
- if ( 0 == strcmp( device_name , item->text(col_r_host_dev_).toStdString().c_str() ) ){
- exists = 1;
- break;
- }
- it++;
-
- }
-
- return exists;
-}
-
-QTreeWidgetItem* ManageInterfacesDialog::getRemoteHostItem( char* name ){
- QTreeWidgetItemIterator it(ui->remoteList);
-
- while (*it) {
- QTreeWidgetItem * item = *it;
-
- if ( item->text(col_r_host_dev_) == QString( name ) ){
- return item;
- }
-
- it++;
- }
-
- QTreeWidgetItem* item = new QTreeWidgetItem(ui->remoteList);
- item->setText(col_r_host_dev_, QString(name));
- item->setExpanded(true);
-
- return item;
-}
-
void ManageInterfacesDialog::showRemoteInterfaces()
{
guint i;
interface_t *device;
- QTreeWidgetItem *item = NULL;
// We assume that remote interfaces are grouped by host.
for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
- QTreeWidgetItem *child;
device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (!device->local) {
+ QList<QTreeWidgetItem*> items = ui->remoteList->findItems(QString(device->name), Qt::MatchCaseSensitive | Qt::MatchFixedString, col_r_host_dev_);
+
// check if the QTreeWidgetItem for that interface already exists
- if ( 1 == remoteInterfacesExists( device->name )){
- continue;
+ if (items.count() == 0) {
+ items = ui->remoteList->findItems(QString(device->remote_opts.remote_host_opts.remote_host),
+ Qt::MatchCaseSensitive | Qt::MatchFixedString, col_r_host_dev_);
+
+ if (items.count() == 0) {
+ // get or create the QTreeWidgetItem for the host
+ QTreeWidgetItem* item = items.at(0);
+ QTreeWidgetItem* child = new QTreeWidgetItem(item);
+ child->setCheckState(col_r_show_, device->hidden ? Qt::Unchecked : Qt::Checked);
+ child->setText(col_r_host_dev_, QString(device->name));
+ }
}
-
- // get or create the QTreeWidgetItem for the host
- item = getRemoteHostItem( device->remote_opts.remote_host_opts.remote_host );
-
- child = new QTreeWidgetItem(item);
- child->setCheckState(col_r_show_, device->hidden ? Qt::Unchecked : Qt::Checked);
- child->setText(col_r_host_dev_, QString(device->name));
}
}
}
diff --git a/ui/qt/manage_interfaces_dialog.h b/ui/qt/manage_interfaces_dialog.h
index 5e0509bdf9..3faee248e3 100644
--- a/ui/qt/manage_interfaces_dialog.h
+++ b/ui/qt/manage_interfaces_dialog.h
@@ -74,8 +74,6 @@ private slots:
void remoteAccepted();
void on_remoteList_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
void on_remoteList_itemClicked(QTreeWidgetItem *item, int column);
- int remoteInterfacesExists(char* device_name);
- QTreeWidgetItem* getRemoteHostItem( char* name );
void addRemoteInterfaces(GList *rlist, remote_options *roptions);
void updateRemoteInterfaceList(GList *rlist, remote_options *roptions);
void setRemoteSettings(interface_t *iface);