diff options
author | Michael Mann <mmann78@netscape.net> | 2019-11-30 22:01:41 -0500 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2019-12-01 17:07:42 +0000 |
commit | e06969455bf561766601cfc3beeaa7fb90ecf44a (patch) | |
tree | db14ebceb1741c80cd4b4532bb1606422610376a | |
parent | faf3118d45b4e2b439b951b6a6be58576243299b (diff) |
Restrict allowed characters in "short name" of heuristic_protos
This is done to limit parsing errors.
Update documentation of function parameters to remove confusion with dissectors.
Bug: 16106
Change-Id: I6b2cd0badaaf6217fb80bdc411a86cad5e6b07ca
Reviewed-on: https://code.wireshark.org/review/35267
Petri-Dish: Michael Mann <mmann78@netscape.net>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
-rw-r--r-- | epan/dissectors/packet-someip.c | 4 | ||||
-rw-r--r-- | epan/dissectors/packet-tcpros.c | 2 | ||||
-rw-r--r-- | epan/packet.c | 33 | ||||
-rw-r--r-- | epan/packet.h | 6 |
4 files changed, 35 insertions, 10 deletions
diff --git a/epan/dissectors/packet-someip.c b/epan/dissectors/packet-someip.c index 6e42dbb216..6e4f159f99 100644 --- a/epan/dissectors/packet-someip.c +++ b/epan/dissectors/packet-someip.c @@ -3298,8 +3298,8 @@ proto_reg_handoff_someip(void) { someip_handle_udp = create_dissector_handle(dissect_someip_udp, proto_someip); someip_handle_tcp = create_dissector_handle(dissect_someip_tcp, proto_someip); - heur_dissector_add("udp", dissect_some_ip_heur_udp, "SOME/IP over UDP Heuristic", "SOME/IP_UDP_Heuristic", proto_someip, HEURISTIC_DISABLE); - heur_dissector_add("tcp", dissect_some_ip_heur_tcp, "SOME/IP over TCP Heuristic", "SOME/IP_TCP_Heuristic", proto_someip, HEURISTIC_DISABLE); + heur_dissector_add("udp", dissect_some_ip_heur_udp, "SOME/IP_UDP_Heuristic", "someip_udp_heur", proto_someip, HEURISTIC_DISABLE); + heur_dissector_add("tcp", dissect_some_ip_heur_tcp, "SOME/IP_TCP_Heuristic", "someip_tcp_heur", proto_someip, HEURISTIC_DISABLE); initialized = TRUE; } else { diff --git a/epan/dissectors/packet-tcpros.c b/epan/dissectors/packet-tcpros.c index 7b55a45973..6b0c12c79e 100644 --- a/epan/dissectors/packet-tcpros.c +++ b/epan/dissectors/packet-tcpros.c @@ -622,7 +622,7 @@ proto_reg_handoff_tcpros(void) /* register as heuristic dissector */ heur_dissector_add("tcp", dissect_tcpros_heur_tcp, "TCPROS over TCP", - "TCPROS_tcp", proto_tcpros, HEURISTIC_DISABLE); + "tcpros_tcp", proto_tcpros, HEURISTIC_DISABLE); } diff --git a/epan/packet.c b/epan/packet.c index 64b2da5935..d508dc3300 100644 --- a/epan/packet.c +++ b/epan/packet.c @@ -2584,6 +2584,28 @@ get_dissector_table_param(const char *name) return sub_dissectors->param; } +static void +check_valid_heur_name_or_fail(const char *heur_name) +{ + gboolean found_invalid = proto_check_field_name(heur_name); + + /* Additionally forbid upper case characters. */ + if (!found_invalid) { + for (guint i = 0; heur_name[i]; i++) { + if (g_ascii_isupper(heur_name[i])) { + found_invalid = TRUE; + break; + } + } + } + + if (found_invalid) { + g_error("Hueristic Protocol internal name \"%s\" has one or more invalid characters." + " Allowed are lowercase, digits, '-', '_' and non-repeating '.'." + " This might be caused by an inappropriate plugin or a development error.", heur_name); + } +} + /* Finds a heuristic dissector table by table name. */ heur_dissector_list_t find_heur_dissector_list(const char *name) @@ -2602,7 +2624,7 @@ heur_dtbl_entry_t* find_heur_dissector_by_unique_short_name(const char *short_na } void -heur_dissector_add(const char *name, heur_dissector_t dissector, const char *display_name, const char *short_name, const int proto, heuristic_enable_e enable) +heur_dissector_add(const char *name, heur_dissector_t dissector, const char *display_name, const char *internal_name, const int proto, heuristic_enable_e enable) { heur_dissector_list_t sub_dissectors = find_heur_dissector_list(name); const char *proto_name; @@ -2646,17 +2668,20 @@ heur_dissector_add(const char *name, heur_dissector_t dissector, const char *dis } } + /* Make sure short_name is "parsing friendly" since it should only be used internally */ + check_valid_heur_name_or_fail(internal_name); + /* Ensure short_name is unique */ - if (g_hash_table_lookup(heuristic_short_names, short_name) != NULL) { + if (g_hash_table_lookup(heuristic_short_names, internal_name) != NULL) { g_error("Duplicate heuristic short_name \"%s\"!" - " This might be caused by an inappropriate plugin or a development error.", short_name); + " This might be caused by an inappropriate plugin or a development error.", internal_name); } hdtbl_entry = g_slice_new(heur_dtbl_entry_t); hdtbl_entry->dissector = dissector; hdtbl_entry->protocol = find_protocol_by_id(proto); hdtbl_entry->display_name = display_name; - hdtbl_entry->short_name = g_strdup(short_name); + hdtbl_entry->short_name = g_strdup(internal_name); hdtbl_entry->list_name = g_strdup(name); hdtbl_entry->enabled = (enable == HEURISTIC_ENABLE); diff --git a/epan/packet.h b/epan/packet.h index 08481f194e..63cffd13c8 100644 --- a/epan/packet.h +++ b/epan/packet.h @@ -512,15 +512,15 @@ WS_DLL_PUBLIC heur_dtbl_entry_t* find_heur_dissector_by_unique_short_name(const /** Add a sub-dissector to a heuristic dissector list. * Call this in the proto_handoff function of the sub-dissector. * - * @param name the name of the "parent" protocol, e.g. "tcp" + * @param name the name of the heuristic dissector table into which to register the dissector, e.g. "tcp" * @param dissector the sub-dissector to be registered * @param display_name the string used to present heuristic to user, e.g. "HTTP over TCP" - * @param short_name the string used for "internal" use to identify heuristic, e.g. "http_tcp" + * @param internal_name the string used for "internal" use to identify heuristic, e.g. "http_tcp" * @param proto the protocol id of the sub-dissector * @param enable initially enabled or not */ WS_DLL_PUBLIC void heur_dissector_add(const char *name, heur_dissector_t dissector, - const char *display_name, const char *short_name, const int proto, heuristic_enable_e enable); + const char *display_name, const char *internal_name, const int proto, heuristic_enable_e enable); /** Remove a sub-dissector from a heuristic dissector list. * Call this in the prefs_reinit function of the sub-dissector. |