diff options
author | Gerald Combs <gerald@wireshark.org> | 2006-11-01 20:32:23 +0000 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2006-11-01 20:32:23 +0000 |
commit | fe557f6296ae3e6884273be507af4b1ff44e640f (patch) | |
tree | 33562ef50f25e766e71c7c4be9fd16d1d66f3220 /epan/proto.c | |
parent | 34d319370e668978aeb3fc2fbd05b912e7accf1e (diff) |
Throw an exception if we try to add more than a million items to the tree.
svn path=/trunk/; revision=19767
Diffstat (limited to 'epan/proto.c')
-rw-r--r-- | epan/proto.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/epan/proto.c b/epan/proto.c index 3f014abba8..3967c7e7cb 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -2643,7 +2643,9 @@ proto_tree_add_int64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint s return pi; } - +/* Throw an exception if we exceed this many tree items. */ +/* XXX - This should probably be a preference */ +#define MAX_TREE_ITEMS (1 * 1000 * 1000) /* Add a field_info struct to the proto_tree, encapsulating it in a proto_node */ static proto_item * proto_tree_add_node(proto_tree *tree, field_info *fi) @@ -2671,6 +2673,14 @@ proto_tree_add_node(proto_tree *tree, field_info *fi) DISSECTOR_ASSERT(tfi == NULL || (tfi->tree_type >= 0 && tfi->tree_type < num_tree_types)); + PTREE_DATA(tree)->count++; + if (PTREE_DATA(tree)->count > MAX_TREE_ITEMS) { + /* Let the exception handler add items to the tree */ + PTREE_DATA(tree)->count = 0; + THROW_MESSAGE(DissectorError, + ep_strdup_printf("More than %d items in the tree -- possible infinite loop", MAX_TREE_ITEMS)); + } + PROTO_NODE_NEW(pnode); pnode->parent = tnode; pnode->finfo = fi; @@ -3087,7 +3097,7 @@ proto_tree_create_root(void) * but for some reason the default 'visible' is not * changed, then we'll find out very quickly. */ pnode->tree_data->visible = FALSE; - + /* Keep track of the number of children */ pnode->tree_data->count = 0; @@ -5109,7 +5119,7 @@ proto_can_match_selected(field_info *finfo, epan_dissect_t *edt) return TRUE; case FT_NONE: /* - * Doesn't have a value, but may still want to test + * Doesn't have a value, but may still want to test * for its presence in a trace */ return TRUE; |