aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-01-23 17:56:42 +0100
committerRoland Knall <rknall@gmail.com>2018-02-14 08:03:10 +0000
commit9198448f9db7b77af8d19f8265d6785fb005dc58 (patch)
tree8ec8f7bfff3f106cff9987807bff644fe4aad949
parentf0db412f57effe6234edc78e1f438b735efae805 (diff)
Qt: fix crash in packet dialog on changing selection
"((capture_file_t *)cap_file_)->edt" is documented in cfile.h to cover the currently selected packet (in the packet list). But in the packet dialog, the packet selection is irrelevant and the data from a different dissection tree must be used. Change-Id: Ieaea3cf862d47540e7f6b6c84c1a2fa6945a877b Fixes: v2.5.0rc0-1532-g56a130a152 ("ByteViewText: Remove epan dependancy") Bug: 14246 Reviewed-on: https://code.wireshark.org/review/25437 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
-rw-r--r--ui/qt/byte_view_tab.cpp37
-rw-r--r--ui/qt/byte_view_tab.h6
-rw-r--r--ui/qt/packet_dialog.cpp2
3 files changed, 35 insertions, 10 deletions
diff --git a/ui/qt/byte_view_tab.cpp b/ui/qt/byte_view_tab.cpp
index 9b945c649e..ab48c75fb3 100644
--- a/ui/qt/byte_view_tab.cpp
+++ b/ui/qt/byte_view_tab.cpp
@@ -28,17 +28,24 @@
// - We might want to add a callback to free_data_sources in so that we
// don't have to blindly call clear().
-ByteViewTab::ByteViewTab(QWidget *parent) :
+ByteViewTab::ByteViewTab(QWidget *parent, epan_dissect_t *edt_fixed) :
QTabWidget(parent),
- cap_file_(0)
+ cap_file_(0),
+ is_fixed_packet_(edt_fixed != NULL),
+ edt_(edt_fixed)
{
setAccessibleName(tr("Packet bytes"));
setTabPosition(QTabWidget::South);
setDocumentMode(true);
- connect(wsApp, SIGNAL(appInitialized()), this, SLOT(connectToMainWindow()));
+ if (!edt_fixed) {
+ connect(wsApp, SIGNAL(appInitialized()), this, SLOT(connectToMainWindow()));
+ }
}
+// Connects the byte view with the main window, acting on changes to the packet
+// list selection. It MUST NOT be used with the packet dialog as that is
+// independent of the selection in the packet list.
void ByteViewTab::connectToMainWindow()
{
connect(this, SIGNAL(fieldSelected(FieldInformation *)),
@@ -108,10 +115,10 @@ void ByteViewTab::addTab(const char *name, tvbuff_t *tvb) {
void ByteViewTab::byteViewTextHovered(int idx)
{
- if ( idx >= 0 && cap_file_ && cap_file_->edt )
+ if ( idx >= 0 && edt_ )
{
tvbuff_t * tvb = VariantPointer<tvbuff_t>::asPtr(sender()->property(tvb_data_property));
- proto_tree * tree = cap_file_->edt->tree;
+ proto_tree * tree = edt_->tree;
if ( tvb && tree )
{
@@ -131,10 +138,10 @@ void ByteViewTab::byteViewTextHovered(int idx)
void ByteViewTab::byteViewTextMarked(int idx)
{
- if ( idx >= 0 && cap_file_ && cap_file_->edt )
+ if ( idx >= 0 && edt_ )
{
tvbuff_t * tvb = VariantPointer<tvbuff_t>::asPtr(sender()->property(tvb_data_property));
- proto_tree * tree = cap_file_->edt->tree;
+ proto_tree * tree = edt_->tree;
if ( tvb && tree )
{
@@ -216,6 +223,20 @@ void ByteViewTab::selectedFrameChanged(int frameNum)
clear();
qDeleteAll(findChildren<ByteViewText *>());
+ if (!is_fixed_packet_) {
+ /* If this is not a fixed packet (not the packet dialog), it must be the
+ * byte view associated with the packet list. */
+ if (cap_file_ && cap_file_->edt) {
+ /* Assumes that this function is called as a result of selecting a
+ * packet in the packet list (PacketList::selectionChanged). That
+ * invokes "cf_select_packet" which will update "cap_file_->edt". */
+ edt_ = cap_file_->edt;
+ } else {
+ /* capture file is closing or packet is deselected. */
+ edt_ = NULL;
+ }
+ }
+
if ( frameNum >= 0 )
{
if ( ! cap_file_ || ! cap_file_->edt )
@@ -225,7 +246,7 @@ void ByteViewTab::selectedFrameChanged(int frameNum)
* really check, if the dissection happened for the correct frame. In the future we might
* rewrite this for directly calling the dissection engine here. */
GSList *src_le;
- for (src_le = cap_file_->edt->pi.data_src; src_le != NULL; src_le = src_le->next) {
+ for (src_le = edt_->pi.data_src; src_le != NULL; src_le = src_le->next) {
struct data_source *source;
char* source_name;
source = (struct data_source *)src_le->data;
diff --git a/ui/qt/byte_view_tab.h b/ui/qt/byte_view_tab.h
index b3144f2886..915d084634 100644
--- a/ui/qt/byte_view_tab.h
+++ b/ui/qt/byte_view_tab.h
@@ -29,7 +29,7 @@ class ByteViewTab : public QTabWidget
Q_OBJECT
public:
- explicit ByteViewTab(QWidget *parent = 0);
+ explicit ByteViewTab(QWidget *parent = 0, epan_dissect_t *edt_fixed = 0);
public slots:
/* Set the capture file */
@@ -47,6 +47,10 @@ signals:
private:
capture_file *cap_file_;
+ bool is_fixed_packet_; /* true if this byte view is related to a single
+ packet in the packet dialog and false if the
+ packet dissection context can change. */
+ epan_dissect_t *edt_; /* Packet dissection result for the currently selected packet. */
void setTabsVisible();
ByteViewText * findByteViewTextForTvb(tvbuff_t * search, int * idx = 0);
diff --git a/ui/qt/packet_dialog.cpp b/ui/qt/packet_dialog.cpp
index f94a5ba2e9..0a6bc1d59e 100644
--- a/ui/qt/packet_dialog.cpp
+++ b/ui/qt/packet_dialog.cpp
@@ -69,7 +69,7 @@ PacketDialog::PacketDialog(QWidget &parent, CaptureFile &cf, frame_data *fdata)
proto_tree_ = new ProtoTree(ui->packetSplitter);
proto_tree_->setRootNode(edt_.tree);
- byte_view_tab_ = new ByteViewTab(ui->packetSplitter);
+ byte_view_tab_ = new ByteViewTab(ui->packetSplitter, &edt_);
byte_view_tab_->setCaptureFile(cap_file_.capFile());
byte_view_tab_->selectedFrameChanged(0);