From d0d15ef5df75bec136c3d3cf2b76a9b4de5d436d Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Mon, 18 Dec 2017 16:55:37 -0800 Subject: Avoid ASN.1 frame.protocols duplication. Some of the ASN.1 dissectors process their data indirectly through dissector tables. Add dissector_try_string_new so that they can do so without appending duplicate entries to frame.protocols. Change-Id: If9e12d81f9d0cc5b3bf19816e675a0fb79d904a6 Reviewed-on: https://code.wireshark.org/review/24886 Reviewed-by: Gerald Combs Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann --- epan/dissectors/asn1/h225/h225.cnf | 2 +- epan/dissectors/asn1/h245/h245.cnf | 4 ++-- epan/dissectors/asn1/ldap/ldap.cnf | 2 +- epan/dissectors/asn1/qsig/qsig.cnf | 2 +- epan/dissectors/asn1/t124/t124.cnf | 4 ++-- epan/dissectors/packet-h225.c | 2 +- epan/dissectors/packet-h245.c | 4 ++-- epan/dissectors/packet-ldap.c | 28 ++++++++-------------------- epan/dissectors/packet-qsig.c | 2 +- epan/dissectors/packet-t124.c | 4 ++-- epan/packet.c | 27 +++++++++++---------------- epan/packet.h | 20 +++++++------------- 12 files changed, 39 insertions(+), 62 deletions(-) diff --git a/epan/dissectors/asn1/h225/h225.cnf b/epan/dissectors/asn1/h225/h225.cnf index 05bf1c3de6..d9a9cfe2a6 100644 --- a/epan/dissectors/asn1/h225/h225.cnf +++ b/epan/dissectors/asn1/h225/h225.cnf @@ -865,7 +865,7 @@ H221NonStandard/manufacturerCode VAL_PTR = &manufacturerCode if (gefx) { ti = proto_tree_add_string(tree, hf_h225_debug_dissector_try_string, tvb, offset>>3, 0, gefx->key); PROTO_ITEM_SET_HIDDEN(ti); - dissector_try_string(gef_name_dissector_table, gefx->key, tvb_new_subset_length_caplen(tvb, offset>>3, 0, 0), actx->pinfo, tree, actx); + dissector_try_string_new(gef_name_dissector_table, gefx->key, tvb_new_subset_length_caplen(tvb, offset>>3, 0, 0), actx->pinfo, tree, FALSE, actx); } actx->private_data = gefx; /* subdissector could overwrite it */ #.END diff --git a/epan/dissectors/asn1/h245/h245.cnf b/epan/dissectors/asn1/h245/h245.cnf index 2dabaaf9ff..e4425a83de 100644 --- a/epan/dissectors/asn1/h245/h245.cnf +++ b/epan/dissectors/asn1/h245/h245.cnf @@ -715,7 +715,7 @@ if (h245_pi != NULL) if (gefx) { ti = proto_tree_add_string(tree, hf_h245_debug_dissector_try_string, tvb, offset>>3, 0, gefx->key); PROTO_ITEM_SET_HIDDEN(ti); - dissector_try_string(gef_name_dissector_table, gefx->key, tvb_new_subset_length_caplen(tvb, offset>>3, 0, 0), actx->pinfo, tree, actx); + dissector_try_string_new(gef_name_dissector_table, gefx->key, tvb_new_subset_length_caplen(tvb, offset>>3, 0, 0), actx->pinfo, tree, FALSE, actx); } actx->private_data = gefx; /* subdissector could overwrite it */ #.END @@ -745,7 +745,7 @@ if (h245_pi != NULL) ti = proto_tree_add_string(tree, hf_h245_debug_dissector_try_string, tvb, offset>>3, 0, gefx->key); PROTO_ITEM_SET_HIDDEN(ti); add_new_data_source(%(ACTX)s->pinfo, value_tvb, "booleanArray"); - dissector_try_string(gef_content_dissector_table, gefx->key, value_tvb, %(ACTX)s->pinfo, %(TREE)s, %(ACTX)s); + dissector_try_string_new(gef_content_dissector_table, gefx->key, value_tvb, %(ACTX)s->pinfo, %(TREE)s, FALSE, %(ACTX)s); } #.END #.FN_BODY ParameterValue/unsignedMin VAL_PTR = &value diff --git a/epan/dissectors/asn1/ldap/ldap.cnf b/epan/dissectors/asn1/ldap/ldap.cnf index e986db7fe9..e4617d859e 100644 --- a/epan/dissectors/asn1/ldap/ldap.cnf +++ b/epan/dissectors/asn1/ldap/ldap.cnf @@ -464,7 +464,7 @@ ldap_conv_info_t *ldap_info; proto_tree_add_item (tree, *hf_id, next_tvb, 0, tvb_reported_length_remaining(next_tvb, 0), ENC_UTF_8|ENC_NA); /* if we have an attribute type that isn't binary see if there is a better dissector */ - else if(!attr_type || !next_tvb || !dissector_try_string(ldap_name_dissector_table, attr_type, next_tvb, actx->pinfo, tree, NULL)) { + else if(!attr_type || !next_tvb || !dissector_try_string_new(ldap_name_dissector_table, attr_type, next_tvb, actx->pinfo, tree, FALSE, NULL)) { offset = old_offset; /* do the default thing */ diff --git a/epan/dissectors/asn1/qsig/qsig.cnf b/epan/dissectors/asn1/qsig/qsig.cnf index 2fd438c23f..abdd580b96 100644 --- a/epan/dissectors/asn1/qsig/qsig.cnf +++ b/epan/dissectors/asn1/qsig/qsig.cnf @@ -146,7 +146,7 @@ NameData TYPE = FT_STRING DISPLAY = BASE_NONE tvbuff_t *next_tvb; next_tvb = tvb_new_subset_remaining(tvb, offset); - if (!dissector_try_string(extension_dissector_table, extension_oid, next_tvb, actx->pinfo, tree, NULL)) { + if (!dissector_try_string_new(extension_dissector_table, extension_oid, next_tvb, actx->pinfo, tree, FALSE, NULL)) { proto_tree *next_tree; next_tree=proto_tree_add_subtree_format(tree, next_tvb, 0, -1, ett_qsig_unknown_extension, NULL, diff --git a/epan/dissectors/asn1/t124/t124.cnf b/epan/dissectors/asn1/t124/t124.cnf index e3a8efa507..363bbcc6f2 100644 --- a/epan/dissectors/asn1/t124/t124.cnf +++ b/epan/dissectors/asn1/t124/t124.cnf @@ -156,7 +156,7 @@ RegistryAllocateHandleResponse/result AllocateHandleResponseResult ns = tvb_get_string_enc(wmem_packet_scope(), t124NSIdentifier, 0, tvb_reported_length(t124NSIdentifier), ENC_ASCII|ENC_NA); if(ns != NULL) { - dissector_try_string(t124_ns_dissector_table, ns, next_tvb, actx->pinfo, top_tree, NULL); + dissector_try_string_new(t124_ns_dissector_table, ns, next_tvb, actx->pinfo, top_tree, FALSE, NULL); } } @@ -169,7 +169,7 @@ RegistryAllocateHandleResponse/result AllocateHandleResponseResult if(next_tvb) { - dissector_try_uint(t124_sd_dissector_table, channelId, next_tvb, actx->pinfo, top_tree); + dissector_try_uint_new(t124_sd_dissector_table, channelId, next_tvb, actx->pinfo, top_tree, FALSE, NULL); } diff --git a/epan/dissectors/packet-h225.c b/epan/dissectors/packet-h225.c index daa879b83e..65fe553597 100644 --- a/epan/dissectors/packet-h225.c +++ b/epan/dissectors/packet-h225.c @@ -3899,7 +3899,7 @@ dissect_h225_GenericIdentifier(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *ac if (gefx) { ti = proto_tree_add_string(tree, hf_h225_debug_dissector_try_string, tvb, offset>>3, 0, gefx->key); PROTO_ITEM_SET_HIDDEN(ti); - dissector_try_string(gef_name_dissector_table, gefx->key, tvb_new_subset_length_caplen(tvb, offset>>3, 0, 0), actx->pinfo, tree, actx); + dissector_try_string_new(gef_name_dissector_table, gefx->key, tvb_new_subset_length_caplen(tvb, offset>>3, 0, 0), actx->pinfo, tree, FALSE, actx); } actx->private_data = gefx; /* subdissector could overwrite it */ diff --git a/epan/dissectors/packet-h245.c b/epan/dissectors/packet-h245.c index a489278dcb..451e3c2462 100644 --- a/epan/dissectors/packet-h245.c +++ b/epan/dissectors/packet-h245.c @@ -3688,7 +3688,7 @@ dissect_h245_ParameterIdentifier(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t * if (gefx) { ti = proto_tree_add_string(tree, hf_h245_debug_dissector_try_string, tvb, offset>>3, 0, gefx->key); PROTO_ITEM_SET_HIDDEN(ti); - dissector_try_string(gef_name_dissector_table, gefx->key, tvb_new_subset_length_caplen(tvb, offset>>3, 0, 0), actx->pinfo, tree, actx); + dissector_try_string_new(gef_name_dissector_table, gefx->key, tvb_new_subset_length_caplen(tvb, offset>>3, 0, 0), actx->pinfo, tree, FALSE, actx); } actx->private_data = gefx; /* subdissector could overwrite it */ @@ -3717,7 +3717,7 @@ dissect_h245_T_booleanArray(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx ti = proto_tree_add_string(tree, hf_h245_debug_dissector_try_string, tvb, offset>>3, 0, gefx->key); PROTO_ITEM_SET_HIDDEN(ti); add_new_data_source(actx->pinfo, value_tvb, "booleanArray"); - dissector_try_string(gef_content_dissector_table, gefx->key, value_tvb, actx->pinfo, tree, actx); + dissector_try_string_new(gef_content_dissector_table, gefx->key, value_tvb, actx->pinfo, tree, FALSE, actx); } diff --git a/epan/dissectors/packet-ldap.c b/epan/dissectors/packet-ldap.c index fafd29277b..67c3414af0 100644 --- a/epan/dissectors/packet-ldap.c +++ b/epan/dissectors/packet-ldap.c @@ -15,19 +15,7 @@ * By Gerald Combs * Copyright 1998 Gerald Combs * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: GPL-2.0+ */ /* @@ -345,7 +333,7 @@ static int hf_ldap_graceAuthNsRemaining = -1; /* INTEGER_0_maxInt */ static int hf_ldap_error = -1; /* T_error */ /*--- End of included file: packet-ldap-hf.c ---*/ -#line 195 "./asn1/ldap/packet-ldap-template.c" +#line 183 "./asn1/ldap/packet-ldap-template.c" /* Initialize the subtree pointers */ static gint ett_ldap = -1; @@ -417,7 +405,7 @@ static gint ett_ldap_PasswordPolicyResponseValue = -1; static gint ett_ldap_T_warning = -1; /*--- End of included file: packet-ldap-ett.c ---*/ -#line 207 "./asn1/ldap/packet-ldap-template.c" +#line 195 "./asn1/ldap/packet-ldap-template.c" static expert_field ei_ldap_exceeded_filter_length = EI_INIT; static expert_field ei_ldap_too_many_filter_elements = EI_INIT; @@ -2369,7 +2357,7 @@ dissect_ldap_AttributeValue(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int of proto_tree_add_item (tree, *hf_id, next_tvb, 0, tvb_reported_length_remaining(next_tvb, 0), ENC_UTF_8|ENC_NA); /* if we have an attribute type that isn't binary see if there is a better dissector */ - else if(!attr_type || !next_tvb || !dissector_try_string(ldap_name_dissector_table, attr_type, next_tvb, actx->pinfo, tree, NULL)) { + else if(!attr_type || !next_tvb || !dissector_try_string_new(ldap_name_dissector_table, attr_type, next_tvb, actx->pinfo, tree, FALSE, NULL)) { offset = old_offset; /* do the default thing */ @@ -3827,7 +3815,7 @@ static int dissect_PasswordPolicyResponseValue_PDU(tvbuff_t *tvb _U_, packet_inf /*--- End of included file: packet-ldap-fn.c ---*/ -#line 913 "./asn1/ldap/packet-ldap-template.c" +#line 901 "./asn1/ldap/packet-ldap-template.c" static int dissect_LDAPMessage_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, ldap_conv_info_t *ldap_info) { int offset = 0; @@ -5638,7 +5626,7 @@ void proto_register_ldap(void) { NULL, HFILL }}, /*--- End of included file: packet-ldap-hfarr.c ---*/ -#line 2155 "./asn1/ldap/packet-ldap-template.c" +#line 2143 "./asn1/ldap/packet-ldap-template.c" }; /* List of subtrees */ @@ -5712,7 +5700,7 @@ void proto_register_ldap(void) { &ett_ldap_T_warning, /*--- End of included file: packet-ldap-ettarr.c ---*/ -#line 2169 "./asn1/ldap/packet-ldap-template.c" +#line 2157 "./asn1/ldap/packet-ldap-template.c" }; /* UAT for header fields */ static uat_field_t custom_attribute_types_uat_fields[] = { @@ -5900,7 +5888,7 @@ proto_reg_handoff_ldap(void) /*--- End of included file: packet-ldap-dis-tab.c ---*/ -#line 2340 "./asn1/ldap/packet-ldap-template.c" +#line 2328 "./asn1/ldap/packet-ldap-template.c" dissector_add_uint_range_with_preference("tcp.port", TCP_PORT_RANGE_LDAP, ldap_handle); } diff --git a/epan/dissectors/packet-qsig.c b/epan/dissectors/packet-qsig.c index feecaa1927..90498d9cd3 100644 --- a/epan/dissectors/packet-qsig.c +++ b/epan/dissectors/packet-qsig.c @@ -2078,7 +2078,7 @@ dissect_qsig_T_extensionArgument(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, i tvbuff_t *next_tvb; next_tvb = tvb_new_subset_remaining(tvb, offset); - if (!dissector_try_string(extension_dissector_table, extension_oid, next_tvb, actx->pinfo, tree, NULL)) { + if (!dissector_try_string_new(extension_dissector_table, extension_oid, next_tvb, actx->pinfo, tree, FALSE, NULL)) { proto_tree *next_tree; next_tree=proto_tree_add_subtree_format(tree, next_tvb, 0, -1, ett_qsig_unknown_extension, NULL, diff --git a/epan/dissectors/packet-t124.c b/epan/dissectors/packet-t124.c index b0027b2f06..dad87c274b 100644 --- a/epan/dissectors/packet-t124.c +++ b/epan/dissectors/packet-t124.c @@ -582,7 +582,7 @@ dissect_t124_T_value(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, pr ns = tvb_get_string_enc(wmem_packet_scope(), t124NSIdentifier, 0, tvb_reported_length(t124NSIdentifier), ENC_ASCII|ENC_NA); if(ns != NULL) { - dissector_try_string(t124_ns_dissector_table, ns, next_tvb, actx->pinfo, top_tree, NULL); + dissector_try_string_new(t124_ns_dissector_table, ns, next_tvb, actx->pinfo, top_tree, FALSE, NULL); } } @@ -2428,7 +2428,7 @@ dissect_t124_T_userData(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, if(next_tvb) { - dissector_try_uint(t124_sd_dissector_table, channelId, next_tvb, actx->pinfo, top_tree); + dissector_try_uint_new(t124_sd_dissector_table, channelId, next_tvb, actx->pinfo, top_tree, FALSE, NULL); } diff --git a/epan/packet.c b/epan/packet.c index 7c9bb1ece5..68f41fc0d6 100644 --- a/epan/packet.c +++ b/epan/packet.c @@ -5,19 +5,7 @@ * By Gerald Combs * Copyright 1998 Gerald Combs * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * SPDX-License-Identifier: GPL-2.0+ */ #include "config.h" @@ -1624,8 +1612,8 @@ dissector_reset_string(const char *name, const gchar *pattern) the dissector with the arguments supplied, and return length of dissected data, otherwise return 0. */ int -dissector_try_string(dissector_table_t sub_dissectors, const gchar *string, - tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) +dissector_try_string_new(dissector_table_t sub_dissectors, const gchar *string, + tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, const gboolean add_proto_name, void *data) { dtbl_entry_t *dtbl_entry; struct dissector_handle *handle; @@ -1656,7 +1644,7 @@ dissector_try_string(dissector_table_t sub_dissectors, const gchar *string, */ saved_match_string = pinfo->match_string; pinfo->match_string = string; - len = call_dissector_work(handle, tvb, pinfo, tree, TRUE, data); + len = call_dissector_work(handle, tvb, pinfo, tree, add_proto_name, data); pinfo->match_string = saved_match_string; /* @@ -1677,6 +1665,13 @@ dissector_try_string(dissector_table_t sub_dissectors, const gchar *string, return 0; } +int +dissector_try_string(dissector_table_t sub_dissectors, const gchar *string, + tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) +{ + return dissector_try_string_new(sub_dissectors, string, tvb, pinfo, tree, TRUE, data); +} + /* Look for a given value in a given string dissector table and, if found, return the dissector handle for that value. */ dissector_handle_t diff --git a/epan/packet.h b/epan/packet.h index 67ed2471b5..e96375e509 100644 --- a/epan/packet.h +++ b/epan/packet.h @@ -5,19 +5,7 @@ * By Gerald Combs * Copyright 1998 Gerald Combs * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * SPDX-License-Identifier: GPL-2.0+ */ #ifndef __PACKET_H__ @@ -303,6 +291,12 @@ WS_DLL_PUBLIC void dissector_reset_string(const char *name, const gchar *pattern WS_DLL_PUBLIC int dissector_try_string(dissector_table_t sub_dissectors, const gchar *string, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data); +/* Look for a given string in a given dissector table and, if found, call + the dissector with the arguments supplied, and return the number of + bytes consumed, otherwise return 0. */ +WS_DLL_PUBLIC int dissector_try_string_new(dissector_table_t sub_dissectors, + const gchar *string, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, const gboolean add_proto_name,void *data); + /** Look for a given value in a given string dissector table and, if found, * return the current dissector handle for that value. * -- cgit v1.2.3