aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Morriss <jeff.morriss.ws@gmail.com>2016-03-30 15:56:21 -0400
committerMichael Mann <mmann78@netscape.net>2016-03-31 03:14:39 +0000
commitfda0bafeb842f77059bce6aa3aa5cabd04f8457d (patch)
tree77e52c2e4136d7373d0d2af6333bd7cdc45f969c
parentd81fe3907b00e00fb05a88eb0812ac874922e835 (diff)
Ensure our fields are registered before starting dissection--even when !tree.
(The check to ensure the delayed field registration had been done was still wrapped inside an if(tree) but a bunch of proto_add_*()'s had been pulled out from under if(tree)'s thus causing some hf's to be used before registered.) Also simplify the code to ensure the fields are registered since we're doing it potentially many times per frame: do an integer comparison rather than looking up an hf by name. Add a note to the docs for proto_register_prefix() to make it clear that the initializer routine may not be called before the dissector is asked to dissect something. Change-Id: I5dc1154638a290c3a94149184d56570c3abb836a Reviewed-on: https://code.wireshark.org/review/14711 Petri-Dish: Jeff Morriss <jeff.morriss.ws@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
-rw-r--r--epan/dissectors/packet-radius.c24
-rw-r--r--epan/proto.h3
2 files changed, 14 insertions, 13 deletions
diff --git a/epan/dissectors/packet-radius.c b/epan/dissectors/packet-radius.c
index 97ae20e8d7..0643a0f923 100644
--- a/epan/dissectors/packet-radius.c
+++ b/epan/dissectors/packet-radius.c
@@ -1357,6 +1357,7 @@ vsa_buffer_table_destroy(void *table)
}
}
+static void register_radius_fields(const char *);
void
dissect_attribute_value_pairs(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, int offset, guint length)
@@ -1371,8 +1372,8 @@ dissect_attribute_value_pairs(proto_tree *tree, packet_info *pinfo, tvbuff_t *tv
GHashTable *vsa_buffer_table = NULL;
- /* Forces load of header fields, if not already done so */
- DISSECTOR_ASSERT(proto_registrar_get_byname("radius.code"));
+ if (hf_radius_code == -1)
+ register_radius_fields("");
/*
* In case we throw an exception, clean up whatever stuff we've
@@ -1763,8 +1764,6 @@ is_radius(tvbuff_t *tvb)
return TRUE;
}
-static void register_radius_fields(const char *);
-
/*
* returns true if the response authenticator is valid
* input: tvb of the reponse, corresponding request authenticator
@@ -1846,16 +1845,15 @@ dissect_radius(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _
val_to_str_ext_const(rh.rh_code, &radius_pkt_type_codes_ext, "Unknown Packet"),
rh.rh_code, rh.rh_ident, rh.rh_pktlength);
- if (tree) {
- /* Forces load of header fields, if not already done so */
- DISSECTOR_ASSERT(proto_registrar_get_byname("radius.code"));
+ /* Load header fields if not already done */
+ if (hf_radius_code == -1)
+ register_radius_fields("");
- ti = proto_tree_add_item(tree, proto_radius, tvb, 0, rh.rh_pktlength, ENC_NA);
- radius_tree = proto_item_add_subtree(ti, ett_radius);
- proto_tree_add_uint(radius_tree, hf_radius_code, tvb, 0, 1, rh.rh_code);
- proto_tree_add_uint_format(radius_tree, hf_radius_id, tvb, 1, 1, rh.rh_ident,
- "Packet identifier: 0x%01x (%d)", rh.rh_ident, rh.rh_ident);
- }
+ ti = proto_tree_add_item(tree, proto_radius, tvb, 0, rh.rh_pktlength, ENC_NA);
+ radius_tree = proto_item_add_subtree(ti, ett_radius);
+ proto_tree_add_uint(radius_tree, hf_radius_code, tvb, 0, 1, rh.rh_code);
+ proto_tree_add_uint_format(radius_tree, hf_radius_id, tvb, 1, 1, rh.rh_ident,
+ "Packet identifier: 0x%01x (%d)", rh.rh_ident, rh.rh_ident);
/*
* Make sure the length is sane.
diff --git a/epan/proto.h b/epan/proto.h
index 54c72a10e8..7d6ce083c2 100644
--- a/epan/proto.h
+++ b/epan/proto.h
@@ -2080,6 +2080,9 @@ proto_deregister_protocol(const char *short_name);
typedef void (*prefix_initializer_t)(const char* match);
/** Register a new prefix for delayed initialization of field arrays
+ Note that the initializer function MAY NOT be called before the dissector
+ is first called. That is, dissectors using this function must be prepared
+ to call the initializer before beginning dissection.
@param prefix the prefix for the new protocol
@param initializer function that will initialize the field array for the given prefix */
WS_DLL_PUBLIC void