Also fake empty field_info's by gracefully handling NULL field_info pointer elsewhere.

svn path=/trunk/; revision=29490
This commit is contained in:
Kovarththanan Rajaratnam 2009-08-21 11:03:30 +00:00
parent 1108352f00
commit 27f7d88c84
10 changed files with 69 additions and 17 deletions

View 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 {

View 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:

View 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. */

2
file.c
View File

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

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

View 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;

View 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)

View 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;

View File

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

View 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.