Also fake empty field_info's by gracefully handling NULL field_info pointer elsewhere.
authorkrj <krj@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 21 Aug 2009 11:03:30 +0000 (11:03 +0000)
committerkrj <krj@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 21 Aug 2009 11:03:30 +0000 (11:03 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@29490 f5534014-38df-0310-8fa8-9805f1628bb7

epan/dissectors/packet-iax2.c
epan/proto.c
epan/proto.h
file.c
gtk/expert_comp_table.c
gtk/main_proto_draw.c
gtk/rtp_analysis.c
plugins/wimax/packet-wmx.c
print.c
proto_hier_stats.c

index 46f71140c58f0ed0f44e88ad93fb61ae005dfd5b..b347125c4e2977bf45f0f5ee2362aff64af275eb 100644 (file)
@@ -1332,7 +1332,7 @@ static guint32 dissect_ies (tvbuff_t * tvb, guint32 offset,
        
        /* if the representation of the item has already been set, use that;
           else we have to allocate a block to put the text into */
-       if( ie_finfo -> rep != NULL ) 
+       if( ie_finfo && ie_finfo->rep != NULL )
          proto_item_set_text(ti, "Information Element: %s",
                              ie_finfo->rep->representation);
        else {
index c36588156576fd1d0145cfa185a546542436dd06..6c70f07c3f0e052ca4726399e0ea2ac8f39f4a76 100644 (file)
@@ -93,9 +93,6 @@ wrs_count_bitshift(guint32 bitmask)
           will still have somewhere to attach to                       \
           or else filtering will not work (they would be ignored since tree\
           would be NULL).                                              \
-          DONT try to fake a node where PTREE_FINFO(tree) is NULL      \
-          since dissectors that want to do proto_item_set_len() or     \
-          other operations that dereference this would crash.          \
           We fake FT_PROTOCOL unless some clients have requested us    \
           not to do so. \
        */                                                              \
@@ -103,14 +100,12 @@ wrs_count_bitshift(guint32 bitmask)
                return(NULL); \
        PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo);       \
        if(!(PTREE_DATA(tree)->visible)){                               \
-               if(PTREE_FINFO(tree)){                                  \
                        if((hfinfo->ref_count == HF_REF_TYPE_NONE)      \
                        && (hfinfo->type!=FT_PROTOCOL ||        \
                                PTREE_DATA(tree)->fake_protocols)){     \
                                /* just return tree back to the caller */\
                                return tree;                            \
                        }                                               \
-               }                                                       \
        }
 
 static gboolean
@@ -2187,6 +2182,8 @@ proto_item_append_string(proto_item *pi, const char *str)
                return;
 
        fi = PITEM_FINFO(pi);
+       DISSECTOR_ASSERT(fi && "proto_tree_set_visible(tree, TRUE) should have been called previously");
+
        hfinfo = fi->hfinfo;
        if (hfinfo->type == FT_PROTOCOL) {
                /* TRY_TO_FAKE_THIS_ITEM() speed optimization: silently skip */
@@ -3130,7 +3127,11 @@ proto_tree_set_representation_value(proto_item *pi, const char *format, va_list
 {
        int     ret;    /*tmp return value */
        field_info *fi = PITEM_FINFO(pi);
-       header_field_info *hf = fi->hfinfo;
+       header_field_info *hf;
+
+       DISSECTOR_ASSERT(fi);
+
+       hf = fi->hfinfo;
 
        if (!PROTO_ITEM_IS_HIDDEN(pi)) {
                ITEM_LABEL_NEW(fi->rep);
@@ -3186,6 +3187,8 @@ proto_tree_set_representation(proto_item *pi, const char *format, va_list ap)
        int                                     ret;    /*tmp return value */
        field_info *fi = PITEM_FINFO(pi);
 
+       DISSECTOR_ASSERT(fi);
+
        if (!PROTO_ITEM_IS_HIDDEN(pi)) {
                ITEM_LABEL_NEW(fi->rep);
                ret = g_vsnprintf(fi->rep->representation, ITEM_LABEL_LENGTH,
@@ -3220,6 +3223,8 @@ proto_item_set_text(proto_item *pi, const char *format, ...)
        }
 
        fi = PITEM_FINFO(pi);
+       if (fi==NULL)
+               return;
 
        if(fi->rep){
                ITEM_LABEL_FREE(fi->rep);
@@ -3275,7 +3280,11 @@ proto_item_set_len(proto_item *pi, gint length)
 
        if (pi == NULL)
                return;
+
        fi = PITEM_FINFO(pi);
+       if (fi == NULL)
+               return;
+
        DISSECTOR_ASSERT(length >= 0);
        fi->length = length;
 
@@ -3297,7 +3306,11 @@ proto_item_set_end(proto_item *pi, tvbuff_t *tvb, gint end)
 
        if (pi == NULL)
                return;
+
        fi = PITEM_FINFO(pi);
+       if (fi == NULL)
+               return;
+
        end += TVB_RAW_OFFSET(tvb);
        DISSECTOR_ASSERT(end >= fi->start);
        fi->length = end - fi->start;
@@ -3307,7 +3320,7 @@ int
 proto_item_get_len(proto_item *pi)
 {
        field_info *fi = PITEM_FINFO(pi);
-       return fi->length;
+       return fi ? fi->length : -1;
 }
 
 
@@ -3334,8 +3347,6 @@ proto_item_set_expert_flags(proto_item *pi, int group, guint severity)
        return FALSE;
 }
 
-
-
 proto_tree*
 proto_tree_create_root(void)
 {
@@ -3401,8 +3412,12 @@ proto_item_add_subtree(proto_item *pi,  gint idx) {
        if (!pi)
                return(NULL);
 
-       fi = PITEM_FINFO(pi);
        DISSECTOR_ASSERT(idx >= 0 && idx < num_tree_types);
+
+       fi = PITEM_FINFO(pi);
+       if (!fi)
+               return (proto_tree*) pi;
+
        fi->tree_type = idx;
 
        return (proto_tree*) pi;
@@ -3460,6 +3475,11 @@ proto_tree_get_root(proto_tree *tree) {
 void
 proto_tree_move_item(proto_tree *tree, proto_item *fixed_item, proto_item *item_to_move)
 {
+       /* This function doesn't generate any values. It only reorganizes the prococol tree
+        * so we can bail out immediately if it isn't visible. */
+       if (!tree || !PTREE_DATA(tree)->visible)
+               return;
+
     DISSECTOR_ASSERT(item_to_move->parent == tree);
     DISSECTOR_ASSERT(fixed_item->parent == tree);
 
@@ -3507,6 +3527,9 @@ proto_tree_set_appendix(proto_tree *tree, tvbuff_t *tvb, gint start, gint length
                return;
 
        fi = PTREE_FINFO(tree);
+       if (fi == NULL)
+               return;
+
        start += TVB_RAW_OFFSET(tvb);
        DISSECTOR_ASSERT(start >= 0);
        DISSECTOR_ASSERT(length >= 0);
@@ -4089,6 +4112,13 @@ proto_item_fill_label(field_info *fi, gchar *label_str)
        const gchar                     *name;
        int                                     ret;    /*tmp return value */
 
+       if (!fi) {
+               if (label_str)
+                       label_str[0]= '\0';
+               /* XXX: Check validity of hfinfo->type */
+               return;
+       }
+
        switch(hfinfo->type) {
                case FT_NONE:
                case FT_PROTOCOL:
index 8b74613f94fe4a206da3a889a32cfbc0d94b063d..20c117d2dad311872d4bfd8d4657043cc27f1b88 100644 (file)
@@ -245,11 +245,10 @@ typedef struct field_info {
 /** The protocol field is actually a URL */
 #define FI_URL                  0x00000004
 
-
 /** convenience macro to get field_info.flags */
-#define FI_GET_FLAG(fi, flag) (fi->flags & flag)
+#define FI_GET_FLAG(fi, flag) ((fi) ? (fi->flags & flag) : 0)
 /** convenience macro to set field_info.flags */
-#define FI_SET_FLAG(fi, flag) (fi->flags = fi->flags | flag)
+#define FI_SET_FLAG(fi, flag) ((fi) ? (fi->flags = fi->flags | flag) : 0)
 
 /** One of these exists for the entire protocol tree. Each proto_node
  * in the protocol tree points to the same copy. */
diff --git a/file.c b/file.c
index ddee0925f78de3b8bc092ef717dfe0b85aacd444..39ae7bf1022f1aa6a211f3dcbaf08544f08f0e6a 100644 (file)
--- a/file.c
+++ b/file.c
@@ -2994,6 +2994,8 @@ match_subtree_text(proto_node *node, gpointer data)
   guint8       c_char;
   size_t       c_match = 0;
 
+  g_assert(fi && "dissection with an invisible proto tree?");
+
   if (mdata->frame_matched) {
     /* We already had a match; don't bother doing any more work. */
     return;
index 8e799b8cf73223356c253ca476e896b29fd9b368..701eb4b50001e77a8a4bbc6f165a90bd622f3aba 100644 (file)
@@ -577,7 +577,8 @@ init_error_table_row(error_equiv_table *err, const expert_info_t *expert_data)
         /* If an expert item was passed then build the filter string */
         if (expert_data->pitem) {
             char *filter;
-
+            
+            g_assert(PITEM_FINFO(expert_data->pitem));
             filter = proto_construct_match_selected_string(PITEM_FINFO(expert_data->pitem), NULL);
             if (filter != NULL)
                 procedure->fvalue_value = g_string_chunk_insert(err->text, filter);
index 1bde6b5755a90d1f86e019303c7ac1060fd9e005..c7d4f3ce2e7e27b7918dcc0e984c40b983db137a 100644 (file)
@@ -1692,6 +1692,8 @@ proto_tree_draw_node(proto_node *node, gpointer data)
     GtkTreeIter   iter;
     GtkTreePath  *path;
 
+    g_assert(fi && "dissection with an invisible proto tree?");
+
     if (PROTO_ITEM_IS_HIDDEN(node) && !prefs.display_hidden_proto_items)
         return;
 
index 7279109ec994c59fb6d6743a593d22f55318eae9..3969a6771a3c39a03fe56d7beaf95a150aac34e5 100644 (file)
@@ -3505,6 +3505,8 @@ static gboolean process_node(proto_node *ptree_node, header_field_info *hfinform
 
        finfo = PNODE_FINFO(ptree_node);
 
+       g_assert(finfo && "Caller passed top of the protocol tree. Expected child node");
+
        if (hfinformation==(finfo->hfinfo)) {
                hfssrc = proto_registrar_get_byname(proto_field);
                if (hfssrc == NULL)
index 5d2f1e9a681bc909b5f0a7acd04bb8004e9a8951..784d9f89bf1b073c53eaa5651557f4c2cf5cc35a 100644 (file)
@@ -642,6 +642,10 @@ proto_tree *add_tlv_subtree(tlv_info_t *this, gint idx, proto_tree *tree, int hf
 
        /* display the TLV name and display the value in hex. Highlight type, length, and value. */
        tlv_item = proto_tree_add_item(tree, hfindex, tvb, start, tlv_value_length, little_endian);
+
+       if (!PITEM_FINFO(tlv_item))
+               return tree;
+
        /* Correct the highlighting. */
        PITEM_FINFO(tlv_item)->start -= tlv_val_offset;
        PITEM_FINFO(tlv_item)->length += tlv_val_offset;
@@ -733,6 +737,10 @@ proto_tree *add_protocol_subtree(tlv_info_t *this, gint idx, proto_tree *tree, i
        message = se_strdup_vprintf(format, ap);
        va_end(ap);
        tlv_item = proto_tree_add_protocol_format(tree, hfindex, tvb, start, length, "%s", message);
+
+       if (!PITEM_FINFO(tlv_item))
+               return tree;
+
        /* Correct the highlighting. */
        PITEM_FINFO(tlv_item)->start -= tlv_val_offset;
        PITEM_FINFO(tlv_item)->length += tlv_val_offset;
diff --git a/print.c b/print.c
index 921f41b10e0047736ae1aa8d05365ff6475b666b..bd00687b51c527433729a28dcde672ba2a590947 100644 (file)
--- a/print.c
+++ b/print.c
@@ -157,6 +157,8 @@ void proto_tree_print_node(proto_node *node, gpointer data)
        gchar           label_str[ITEM_LABEL_LENGTH];
        gchar           *label_ptr;
 
+       g_assert(fi && "dissection with an invisible proto tree?");
+
        /* Don't print invisible entries. */
        if (PROTO_ITEM_IS_HIDDEN(node))
                return;
@@ -266,10 +268,13 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
        char            *dfilter_string;
        size_t          chop_len;
        int             i;
+       gboolean wrap_in_fake_protocol;
+
+       g_assert(fi && "dissection with an invisible proto tree?");
 
        /* Will wrap up top-level field items inside a fake protocol wrapper to
           preserve the PDML schema */
-       gboolean wrap_in_fake_protocol =
+       wrap_in_fake_protocol =
            (((fi->hfinfo->type != FT_PROTOCOL) ||
             (fi->hfinfo->id == proto_data)) &&
            (pdata->level == 0));
@@ -1417,6 +1422,8 @@ static void proto_tree_get_node_field_values(proto_node *node, gpointer data)
     call_data = data;
     fi = PNODE_FINFO(node);
 
+    g_assert(fi && "dissection with an invisible proto tree?");
+
     field_index = g_hash_table_lookup(call_data->fields->field_indicies, fi->hfinfo->abbrev);
     if(NULL != field_index) {
         const gchar* value;
index edbad8c265cfc2f1ec04782a1f3fe3fab61aedbc..de8510e67cd386b4d9be4b919f3cb3d211098d20 100644 (file)
@@ -86,7 +86,8 @@ process_node(proto_node *ptree_node, GNode *parent_stat_node, ph_stats_t *ps, gu
        GNode                   *stat_node;
 
        finfo = PNODE_FINFO(ptree_node);
-       g_assert(finfo);
+       /* We don't fake protocol nodes we expect them to have a field_info */
+       g_assert(finfo && "dissection with faked proto tree?");
 
        /* If the field info isn't related to a protocol but to a field,
         * don't count them, as they don't belong to any protocol.