aboutsummaryrefslogtreecommitdiffstats
path: root/epan/proto.c
diff options
context:
space:
mode:
authorPascal Quantin <pascal.quantin@gmail.com>2016-09-22 20:14:25 +0200
committerPascal Quantin <pascal.quantin@gmail.com>2016-09-22 18:56:17 +0000
commitcf12e448b1721143d0232c5d866a973862cab139 (patch)
tree6c7fcce25de6438ce7628042e07af7b01a5301e6 /epan/proto.c
parent7477e1c3b90cedfe0d154f5b4c8eb9e5d7e26b59 (diff)
proto.c: avoid dereferencing a NULL pointer
Some sub protocols do not register fields Follow-up of gf4a521e Change-Id: Iec3165d6204cc6acc0ec31a7266f860012463cd0 Reviewed-on: https://code.wireshark.org/review/17868 Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com> Reviewed-by: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
Diffstat (limited to 'epan/proto.c')
-rw-r--r--epan/proto.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/epan/proto.c b/epan/proto.c
index f4ba545002..d0763d490c 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -583,7 +583,9 @@ proto_cleanup(void)
DISSECTOR_ASSERT(protocol->proto_id == hfinfo->id);
g_slice_free(header_field_info, hfinfo);
- g_ptr_array_free(protocol->fields, TRUE);
+ if (protocol->fields) {
+ g_ptr_array_free(protocol->fields, TRUE);
+ }
g_list_free(protocol->heur_list);
protocols = g_list_remove(protocols, protocol);
g_free(protocol);
@@ -5767,7 +5769,7 @@ proto_register_protocol(const char *name, const char *short_name,
protocol->short_name = short_name;
protocol->filter_name = filter_name;
/*protocol->fields = g_ptr_array_new();*/
- /* Delegate until actually needed and use g_ptr_array_new_seized*/
+ /* Delegate until actually needed and use g_ptr_array_sized_new*/
protocol->fields = NULL;
protocol->is_enabled = TRUE; /* protocol is enabled by default */
protocol->enabled_by_default = TRUE; /* see previous comment */
@@ -5815,14 +5817,16 @@ proto_deregister_protocol(const char *short_name)
g_hash_table_remove(proto_short_names, (gpointer)short_name);
g_hash_table_remove(proto_filter_names, (gpointer)protocol->filter_name);
- for (i = 0; i < protocol->fields->len; i++) {
- hfinfo = (header_field_info *)g_ptr_array_index(protocol->fields, i);
- hfinfo_remove_from_gpa_name_map(hfinfo);
- expert_deregister_expertinfo(hfinfo->abbrev);
- g_ptr_array_add(deregistered_fields, gpa_hfinfo.hfi[hfinfo->id]);
+ if (protocol->fields) {
+ for (i = 0; i < protocol->fields->len; i++) {
+ hfinfo = (header_field_info *)g_ptr_array_index(protocol->fields, i);
+ hfinfo_remove_from_gpa_name_map(hfinfo);
+ expert_deregister_expertinfo(hfinfo->abbrev);
+ g_ptr_array_add(deregistered_fields, gpa_hfinfo.hfi[hfinfo->id]);
+ }
+ g_ptr_array_free(protocol->fields, TRUE);
+ protocol->fields = NULL;
}
- g_ptr_array_free(protocol->fields, TRUE);
- protocol->fields = NULL;
/* Remove this protocol from the list of known protocols */
protocols = g_list_remove(protocols, protocol);
@@ -5890,7 +5894,7 @@ proto_get_first_protocol_field(const int proto_id, void **cookie)
{
protocol_t *protocol = find_protocol_by_id(proto_id);
- if ((protocol == NULL) || (protocol->fields->len == 0))
+ if ((protocol == NULL) || (protocol->fields == NULL))
return NULL;
*cookie = GUINT_TO_POINTER(0 + 1);
@@ -5905,7 +5909,7 @@ proto_get_next_protocol_field(const int proto_id, void **cookie)
i++;
- if (i >= protocol->fields->len)
+ if ((protocol->fields == NULL) || (i >= protocol->fields->len))
return NULL;
*cookie = GUINT_TO_POINTER(i + 1);
@@ -6277,7 +6281,7 @@ proto_deregister_field (const int parent, gint hf_id)
return;
proto = find_protocol_by_id (parent);
- if (!proto || proto->fields->len == 0) {
+ if (!proto || proto->fields == NULL) {
return;
}