diff options
author | Jeff Morriss <jeff.morriss.ws@gmail.com> | 2013-06-03 22:07:21 +0000 |
---|---|---|
committer | Jeff Morriss <jeff.morriss.ws@gmail.com> | 2013-06-03 22:07:21 +0000 |
commit | 838e3767ceb2f20a39f5f6aa77ded4628b22fe21 (patch) | |
tree | 5cc7263294657c376f8fbe1899da39f4adc851cf /epan/prefs.c | |
parent | 9475131092bb928813466591a0dd13ecd6b7c36b (diff) |
From Cal Turney via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8707 :
As suggested by Jakub, don't use strlen() when g_string->len will do.
From me:
Don't assume that just because we "got_val" that the value has a length.
Checking it first eliminates this warning from Valgrind:
==11954== Invalid read of size 1
==11954== at 0x61D1466: read_prefs_file (prefs.c:3012)
==11954== by 0x61D1841: read_prefs (prefs.c:2955)
==11954== by 0x409901: main (tshark.c:1137)
==11954== Address 0xc05244f is 1 bytes before a block of size 16 alloc'd
==11954== at 0x4A08A6E: realloc (vg_replace_malloc.c:662)
==11954== by 0x3CF8C4D736: g_realloc (in /usr/lib64/libglib-2.0.so.0.3400.2)
==11954== by 0x3CF8C66226: ??? (in /usr/lib64/libglib-2.0.so.0.3400.2)
==11954== by 0x3CF8C66ACE: g_string_insert_c (in /usr/lib64/libglib-2.0.so.0.3400.2)
==11954== by 0x61D1566: read_prefs_file (gstring.h:139)
==11954== by 0x61D1841: read_prefs (prefs.c:2955)
==11954== by 0x409901: main (tshark.c:1137)
svn path=/trunk/; revision=49731
Diffstat (limited to 'epan/prefs.c')
-rw-r--r-- | epan/prefs.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/epan/prefs.c b/epan/prefs.c index 5725f7439f..ca89935852 100644 --- a/epan/prefs.c +++ b/epan/prefs.c @@ -72,8 +72,8 @@ static gboolean parse_column_format(fmt_data *cfmt, const char *fmt); static void try_convert_to_custom_column(gpointer *el_data); -#define PF_NAME "preferences" -#define OLD_GPF_NAME "wireshark.conf" /* old name for global preferences file */ +#define PF_NAME "preferences" +#define OLD_GPF_NAME "wireshark.conf" /* old name for global preferences file */ static gboolean prefs_initialized = FALSE; static gboolean prefs_pre_initialized = FALSE; @@ -1316,7 +1316,7 @@ static prefs_set_pref_e column_hidden_set_cb(pref_t* pref, const gchar* value, g fmt_data *cfmt; pref_t *format_pref; - if (*pref->varp.string) { + if (*pref->varp.string) { if (strcmp(*pref->varp.string, value) != 0) { *changed = TRUE; g_free((void *)*pref->varp.string); @@ -1324,7 +1324,7 @@ static prefs_set_pref_e column_hidden_set_cb(pref_t* pref, const gchar* value, g } } else if (value) { *pref->varp.string = g_strdup(value); - } + } /* * Set the "visible" flag for the existing columns; we need to @@ -3009,12 +3009,14 @@ read_prefs_file(const char *pf_path, FILE *pf, if (isalnum(got_c)) { if (cur_var->len > 0) { if (got_val) { - if (cur_val->str[strlen(cur_val->str)-1] == ',') { - /* - * If the pref has a trailing comma, eliminate it. - */ - cur_val->str[strlen(cur_val->str)-1] = '\0'; - g_warning ("%s line %d: trailing comma in \"%s\" %s", pf_path, pline, cur_var->str, hint); + if (cur_val->len > 0) { + if (cur_val->str[cur_val->len-1] == ',') { + /* + * If the pref has a trailing comma, eliminate it. + */ + cur_val->str[cur_val->len-1] = '\0'; + g_warning ("%s line %d: trailing comma in \"%s\" %s", pf_path, pline, cur_var->str, hint); + } } /* Call the routine to set the preference; it will parse the value as appropriate. */ |