diff options
author | Gerald Combs <gerald@wireshark.org> | 2009-09-08 22:56:55 +0000 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2009-09-08 22:56:55 +0000 |
commit | c238175acfa256b614a02bc85403c9ce9f173aac (patch) | |
tree | fb54af7b66f5d7cb9b16b979e829b1c6458d0af8 /epan/proto.c | |
parent | c96804223f5eaa6a1492781ef9185b66cbb70189 (diff) |
Move the infinite loop check from proto_tree_add_node to
TRY_TO_FAKE_THIS_ITEM. Partial fix for bug 3986.
svn path=/trunk/; revision=29811
Diffstat (limited to 'epan/proto.c')
-rw-r--r-- | epan/proto.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/epan/proto.c b/epan/proto.c index 118fa6e733..5388d6d7bd 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -51,6 +51,9 @@ #define SUBTREE_ONCE_ALLOCATION_NUMBER 8 #define SUBTREE_MAX_LEVELS 256 +/* Throw an exception if we exceed this many tree items. */ +/* XXX - This should probably be a preference */ +#define MAX_TREE_ITEMS (1 * 1000 * 1000) typedef struct __subtree_lvl { @@ -96,12 +99,19 @@ wrs_count_bitshift(guint32 bitmask) We fake FT_PROTOCOL unless some clients have requested us \ not to do so. \ */ \ - if (!tree) \ - return(NULL); \ - PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo); \ + if (!tree) \ + return(NULL); \ + 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_REGISTRAR_GET_NTH(hfindex, hfinfo); \ if(!(PTREE_DATA(tree)->visible)){ \ if((hfinfo->ref_count != HF_REF_TYPE_DIRECT) \ - && (hfinfo->type!=FT_PROTOCOL || \ + && (hfinfo->type!=FT_PROTOCOL || \ PTREE_DATA(tree)->fake_protocols)){ \ /* just return tree back to the caller */\ return tree; \ @@ -2921,9 +2931,6 @@ 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) @@ -2951,14 +2958,6 @@ 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(pnode) = fi; |