From a016cd7740d81bf493014a8195dc099cadfc6d66 Mon Sep 17 00:00:00 2001 From: Jakub Zawadzki Date: Tue, 18 Sep 2012 19:29:00 +0000 Subject: Revert r44978: dissector_add_uint: Legalize formerly improper use of the API when calling it with pattern value of 0 dissector_add_uint() is *not only* used by tcp.port/udp.port dissector tables where 0 is not valid port number, in some dissector tables 0 is valid protocol number, packet type, etc.. Sample dissectors using dissector_add_uint(.pattern = 0): packet-ansi_637.c:2348: dissector_add_uint("ansi_a.sms", 0, ansi_637_trans_handle); packet-cip.c:6017: dissector_add_uint("cip.class.iface", 0, cip_class_generic_handle ); packet-lon.c:723: dissector_add_uint("cnip.protocol", 0, lon_handle); packet-q931.c:3599: dissector_add_uint("lapd.sapi", LAPD_SAPI_Q931 /* 0 */, q931_handle); svn path=/trunk/; revision=44980 --- epan/packet.c | 85 +++++++++++++++++++++++++++-------------------------------- 1 file changed, 39 insertions(+), 46 deletions(-) (limited to 'epan/packet.c') diff --git a/epan/packet.c b/epan/packet.c index a6f48bf68c..85d7768694 100644 --- a/epan/packet.c +++ b/epan/packet.c @@ -735,63 +735,56 @@ dissector_add_uint_sanity_check(const char *name, guint32 pattern, dissector_han void dissector_add_uint(const char *name, const guint32 pattern, dissector_handle_t handle) { + dissector_table_t sub_dissectors; + dtbl_entry_t *dtbl_entry; + + sub_dissectors = find_dissector_table(name); + /* - * Legalize formerly improper use of the API when calling it with - * a pattern value of 0 - */ - if (pattern) { - dissector_table_t sub_dissectors; - dtbl_entry_t *dtbl_entry; + * Make sure the dissector table exists. + */ + if (sub_dissectors == NULL) { + fprintf(stderr, "OOPS: dissector table \"%s\" doesn't exist\n", + name); + fprintf(stderr, "Protocol being registered is \"%s\"\n", + proto_get_protocol_long_name(handle->protocol)); + if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL) + abort(); + return; + } - sub_dissectors = find_dissector_table(name); + /* sanity checks */ + g_assert(handle!=NULL); + switch (sub_dissectors->type) { + case FT_UINT8: + case FT_UINT16: + case FT_UINT24: + case FT_UINT32: /* - * Make sure the dissector table exists. + * You can do a uint lookup in these tables. */ - if (sub_dissectors == NULL) { - fprintf(stderr, "OOPS: dissector table \"%s\" doesn't exist\n", - name); - fprintf(stderr, "Protocol being registered is \"%s\"\n", - proto_get_protocol_long_name(handle->protocol)); - if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL) - abort(); - return; - } - - /* sanity checks */ - g_assert(handle!=NULL); - switch (sub_dissectors->type) { - - case FT_UINT8: - case FT_UINT16: - case FT_UINT24: - case FT_UINT32: - /* - * You can do a uint lookup in these tables. - */ - break; + break; - default: - /* - * But you can't do a uint lookup in any other types - * of tables. - */ - g_assert_not_reached(); - } + default: + /* + * But you can't do a uint lookup in any other types + * of tables. + */ + g_assert_not_reached(); + } #if 0 - dissector_add_uint_sanity_check(name, pattern, handle, sub_dissectors); + dissector_add_uint_sanity_check(name, pattern, handle, sub_dissectors); #endif - dtbl_entry = g_malloc(sizeof (dtbl_entry_t)); - dtbl_entry->current = handle; - dtbl_entry->initial = dtbl_entry->current; - - /* do the table insertion */ - g_hash_table_insert( sub_dissectors->hash_table, - GUINT_TO_POINTER( pattern), (gpointer)dtbl_entry); + dtbl_entry = g_malloc(sizeof (dtbl_entry_t)); + dtbl_entry->current = handle; + dtbl_entry->initial = dtbl_entry->current; - } + /* do the table insertion */ + g_hash_table_insert( sub_dissectors->hash_table, + GUINT_TO_POINTER( pattern), (gpointer)dtbl_entry); /* * Now add it to the list of handles that could be used with this -- cgit v1.2.3