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 /epan/packet.c | |
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>
Diffstat (limited to 'epan/packet.c')
-rw-r--r-- | epan/packet.c | 33 |
1 files changed, 29 insertions, 4 deletions
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); |