aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-tpncp.c
diff options
context:
space:
mode:
authorMartin Kaiser <wireshark@kaiser.cx>2016-10-22 12:02:50 +0200
committerMichael Mann <mmann78@netscape.net>2016-10-22 19:17:54 +0000
commit48972d883fb8865e37b83a8b8ded2ff270ca9b38 (patch)
tree159511a9fa8bc54bee12d7d228459d4609413e3c /epan/dissectors/packet-tpncp.c
parent49a525a97e68f9ba5b840c3054669a5dd6081010 (diff)
tpncp: load hf array in the handoff function
tpncp reads hf entries from a database. There's a boolean preference defining if the database is actually read. We can't access this preference until the preferences are initialized. The code as it is now wil always default to false and never read the database. Check the preference in the handoff function and initialize the hf entries if they are not yet initialized. Change-Id: I545a49a946b78e1a0bc23e9803eb671d8765bba4 Reviewed-on: https://code.wireshark.org/review/18386 Reviewed-by: Martin Kaiser <wireshark@kaiser.cx> Petri-Dish: Martin Kaiser <wireshark@kaiser.cx> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/dissectors/packet-tpncp.c')
-rw-r--r--epan/dissectors/packet-tpncp.c69
1 files changed, 37 insertions, 32 deletions
diff --git a/epan/dissectors/packet-tpncp.c b/epan/dissectors/packet-tpncp.c
index 82828c4f4b..055172df04 100644
--- a/epan/dissectors/packet-tpncp.c
+++ b/epan/dissectors/packet-tpncp.c
@@ -105,7 +105,7 @@ static guint global_tpncp_trunkpack_tcp_port = TCP_PORT_TPNCP_TRUNKPACK;
static guint global_tpncp_trunkpack_udp_port = UDP_PORT_TPNCP_TRUNKPACK;
static guint global_tpncp_host_tcp_port = TCP_PORT_TPNCP_HOST;
static guint global_tpncp_host_udp_port = UDP_PORT_TPNCP_HOST;
-static guint global_tpncp_load_db = FALSE;
+static gboolean global_tpncp_load_db = FALSE;
static dissector_handle_t tpncp_handle;
@@ -760,6 +760,7 @@ done:
void proto_reg_handoff_tpncp(void) {
static gint tpncp_prefs_initialized = FALSE;
static dissector_handle_t tpncp_tcp_handle;
+ gint idx;
/* If we weren't able to load the database (and thus the hf_ entries)
* do not attach to any ports (if we did then we'd get a "dissector bug"
@@ -782,6 +783,34 @@ void proto_reg_handoff_tpncp(void) {
}
if(global_tpncp_load_db){
+ if (hf_allocated == 0) {
+ if (init_tpncp_db() == -1) {
+ report_failure("tpncp: Could not load tpncp.dat file, tpncp dissector will not work");
+ return;
+ }
+
+ /* Rather than duplicating large quantities of code from
+ * proto_register_field_array() and friends to sanitize the tpncp.dat file
+ * when we read it, just catch any exceptions we get while registering and
+ * take them as a hint that the file is corrupt. Then move on, so that at
+ * least the rest of the protocol dissectors will still work.
+ */
+ TRY {
+ /* The function proto_register_field_array does not work with dynamic
+ * arrays, so pass dynamic array elements one-by-one in the loop.
+ */
+ for(idx = 0; idx < hf_size; idx++) {
+ proto_register_field_array(proto_tpncp, &hf[idx], 1);
+ }
+ }
+
+ CATCH_ALL {
+ report_failure("Corrupt tpncp.dat file, tpncp dissector will not work.");
+ }
+
+ ENDTRY;
+ }
+
trunkpack_tcp_port = global_tpncp_trunkpack_tcp_port;
trunkpack_udp_port = global_tpncp_trunkpack_udp_port;
@@ -796,50 +825,26 @@ void proto_reg_handoff_tpncp(void) {
/*-------------------------------------------------------------------------------------------------------------------------------------------*/
void proto_register_tpncp(void) {
- gint idx;
module_t *tpncp_module;
static gint *ett[] = {
&ett_tpncp,
&ett_tpncp_body
};
+ /* this dissector reads hf entries from a database
+ a boolean preference defines whether the database is loaded or not
+ we initialize the hf array in the handoff function when we have
+ access to the preference's value */
+
proto_tpncp = proto_register_protocol("AudioCodes TPNCP (TrunkPack Network Control Protocol)",
"TPNCP", "tpncp");
- if(global_tpncp_load_db){
- if (init_tpncp_db() == -1) {
- report_failure("tpncp: Could not load tpncp.dat file, tpncp dissector will not work");
- return;
- }
-
-
- /* Rather than duplicating large quantities of code from
- * proto_register_field_array() and friends to sanitize the tpncp.dat file
- * when we read it, just catch any exceptions we get while registering and
- * take them as a hint that the file is corrupt. Then move on, so that at
- * least the rest of the protocol dissectors will still work.
- */
- TRY {
- /* The function proto_register_field_array does not work with dynamic
- * arrays, so pass dynamic array elements one-by-one in the loop.
- */
- for(idx = 0; idx < hf_size; idx++) {
- proto_register_field_array(proto_tpncp, &hf[idx], 1);
- }
- }
-
- CATCH_ALL {
- report_failure("Corrupt tpncp.dat file, tpncp dissector will not work.");
- }
-
- ENDTRY;
-
- proto_register_subtree_array(ett, array_length(ett));
- }
tpncp_handle = register_dissector("tpncp", dissect_tpncp, proto_tpncp);
tpncp_module = prefs_register_protocol(proto_tpncp, proto_reg_handoff_tpncp);
+ proto_register_subtree_array(ett, array_length(ett));
+
/* See https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9569 for some discussion on this as well */
prefs_register_bool_preference(tpncp_module, "load_db",
"Whether to load DB or not; if DB not loaded dissector is passive",