From 7b37c5c180eff710c49ee324869c9ad4dc5c7262 Mon Sep 17 00:00:00 2001 From: Martin Boye Petersen Date: Fri, 7 Sep 2018 09:29:39 +0200 Subject: [PATCH] Qt: Add null check for finfo and hfinfo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding the null check fixes a bug that made wireshark crash when right clicking a subtree which doesn't have any preferences and if none of the parents had one either. The problem was introduced in commit 589413d8772f1450be9bd4a2550cb99a95f71299 Change-Id: Ia5bbae0a58298f3e9d912e44f33589da1cbfacc9 Reviewed-on: https://code.wireshark.org/review/29455 Petri-Dish: Stig Bjørlykke Tested-by: Petri Dish Buildbot Reviewed-by: Stig Bjørlykke --- ui/qt/proto_tree.cpp | 3 ++- ui/qt/utils/field_information.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ui/qt/proto_tree.cpp b/ui/qt/proto_tree.cpp index c97a172d96..e333926d43 100644 --- a/ui/qt/proto_tree.cpp +++ b/ui/qt/proto_tree.cpp @@ -184,8 +184,9 @@ void ProtoTree::contextMenuEvent(QContextMenuEvent *event) // The "text only" header field will not give preferences for the selected protocol. // Use parent in this case. proto_node *node = proto_tree_model_->protoNodeFromIndex(index).protoNode(); - while (node && node->finfo->hfinfo->id == hf_text_only) + while (node && node->finfo && node->finfo->hfinfo && node->finfo->hfinfo->id == hf_text_only) node = node->parent; + FieldInformation pref_finfo(node); proto_prefs_menu_.setModule(pref_finfo.moduleName()); diff --git a/ui/qt/utils/field_information.cpp b/ui/qt/utils/field_information.cpp index d671106cf7..876f8bdb6f 100644 --- a/ui/qt/utils/field_information.cpp +++ b/ui/qt/utils/field_information.cpp @@ -15,7 +15,7 @@ FieldInformation::FieldInformation(field_info *fi, QObject * parent) :QObject(parent) { fi_ = fi; - parent_fi_ = 0; + parent_fi_ = NULL; } FieldInformation::FieldInformation(proto_node *node, QObject * parent) @@ -34,7 +34,7 @@ bool FieldInformation::isValid() const if ( fi_ && fi_->hfinfo ) { - if (fi_->hfinfo->blurb != 0 && fi_->hfinfo->blurb[0] != '\0') { + if (fi_->hfinfo->blurb != NULL && fi_->hfinfo->blurb[0] != '\0') { ret = true; } else { ret = QString((fi_->hfinfo->name)).length() > 0;