diff options
author | Gerald Combs <gerald@wireshark.org> | 2016-09-20 14:11:29 -0700 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2016-12-01 01:26:39 +0000 |
commit | cbf89c8ed842a58c282872cf8c42adf9b8b2ffee (patch) | |
tree | 3a0c338486818e511d8b9f27b0d16b3b213bcf9d /epan/prefs.c | |
parent | 9887cd7feb7c377a3d046b924fe86907479be413 (diff) |
Check preference titles and descriptions.
When registering preferences, make sure our titles and descriptions are
valid UTF-8. Make sure our titles are short and only contain printable
characters.
Fix problematic titles and descriptions.
Change-Id: I20d3f93438f2b3c30266f934297feb79897f2ee5
Reviewed-on: https://code.wireshark.org/review/18998
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/prefs.c')
-rw-r--r-- | epan/prefs.c | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/epan/prefs.c b/epan/prefs.c index 43eec4d726..ee227896a1 100644 --- a/epan/prefs.c +++ b/epan/prefs.c @@ -787,6 +787,7 @@ register_preference(module_t *module, const char *name, const char *title, { pref_t *preference; const gchar *p; + const char *name_prefix = (module->name != NULL) ? module->name : module->parent->name; preference = g_new(pref_t,1); preference->name = name; @@ -834,9 +835,32 @@ register_preference(module_t *module, const char *name, const char *title, g_error("Preference %s begins with the module name", name); } + /* The title shows up in the preferences dialog. Make sure it's UI-friendly. */ + if (preference->title) { + const char *cur_char; + if (preference->type != PREF_STATIC_TEXT && strlen(preference->title) > 80) { // Arbitrary. + g_error("Title for preference %s.%s is too long: %s", name_prefix, preference->name, preference->title); + } + + if (!g_utf8_validate(preference->title, -1, NULL)) { + g_error("Title for preference %s.%s isn't valid UTF-8.", name_prefix, preference->name); + } + + for (cur_char = preference->title; *cur_char; cur_char = g_utf8_next_char(cur_char)) { + if (!g_unichar_isprint(g_utf8_get_char(cur_char))) { + g_error("Title for preference %s.%s isn't printable UTF-8.", name_prefix, preference->name); + } + } + } + + if (preference->description) { + if (!g_utf8_validate(preference->description, -1, NULL)) { + g_error("Description for preference %s.%s isn't valid UTF-8.", name_prefix, preference->name); + } + } + /* - * There isn't already one with that name, so add the - * preference. + * We passed all of our checks. Add the preference. */ module->prefs = g_list_append(module->prefs, preference); if (title != NULL) @@ -2436,13 +2460,15 @@ prefs_register_modules(void) (gint*)(void*)(&prefs.gui_version_placement), gui_version_placement_type, FALSE); prefs_register_bool_preference(gui_module, "auto_scroll_on_expand", - "Automatically scroll the recently expanded item", - "Automatically scroll the recently expanded item", + "Automatically scroll packet details", + "When selecting a new packet, automatically scroll" + "to the packet detail item that matches the most" + "recently selected item", &prefs.gui_auto_scroll_on_expand); prefs_register_uint_preference(gui_module, "auto_scroll_percentage", - "The percentage down the view the recently expanded item should be scrolled", - "The percentage down the view the recently expanded item should be scrolled", + "Packet detail scroll percentage", + "The percentage down the view the recently expanded detail item should be scrolled", 10, &prefs.gui_auto_scroll_percentage); @@ -5357,6 +5383,7 @@ write_pref(gpointer data, gpointer user_data) int type; type = pref->type; + if (IS_PREF_OBSOLETE(type)) { /* * This preference is no longer supported; it's not a |