Qt: Fix ASAN heap-use-after-free

This commit is contained in:
Roland Knall 2022-02-11 18:51:54 +00:00 committed by A Wireshark GitLab Utility
parent 52955b9c43
commit 699c3c051a
2 changed files with 13 additions and 51 deletions

View File

@ -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));
}
}
}

View File

@ -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);