diff options
author | Peter Wu <peter@lekensteyn.nl> | 2015-02-14 17:59:27 +0100 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2015-02-15 22:52:27 +0000 |
commit | f5902a677e24ff96869d3c335f4fb8aaa6d0e543 (patch) | |
tree | f0e81b898f05fb2df3a2e28c7c49a1328d92de91 /epan | |
parent | fea325d2ba86cee47bb6bf89a068906744701c88 (diff) |
Fix duplicate Display Filter Macro check
Since commit 4a1bd75b60171d781dc9f2d3ffd6d498acc74b1a
(https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7471), the data
pointer does not match anything from the macros array.
This patch fixes a false warning by checking for duplicates before the
name is committed.
Bug: 10957
Change-Id: Id61110bf63de1de80b85524705a2df6a5e7be33a
Reviewed-on: https://code.wireshark.org/review/7119
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan')
-rw-r--r-- | epan/dfilter/dfilter-macro.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/epan/dfilter/dfilter-macro.c b/epan/dfilter/dfilter-macro.c index 7f805859ad..234e2cea00 100644 --- a/epan/dfilter/dfilter-macro.c +++ b/epan/dfilter/dfilter-macro.c @@ -403,7 +403,7 @@ const gchar* dfilter_macro_apply(const gchar* text, gchar** error) { return dfilter_macro_apply_recurse(text, 0, error); } -static void macro_update(void* mp, gchar** error) { +static void macro_update(void* mp, gchar** error _U_) { dfilter_macro_t* m = (dfilter_macro_t*)mp; GPtrArray* parts; GArray* args_pos; @@ -411,22 +411,9 @@ static void macro_update(void* mp, gchar** error) { gchar* w; gchar* part; int argc = 0; - guint i; DUMP_MACRO(m); - *error = NULL; - - for (i = 0; i < num_macros; i++) { - if (m == &(macros[i])) continue; - - if ( g_str_equal(m->name,macros[i].name) ) { - *error = g_strdup_printf("macro '%s' exists already", m->name); - m->usable = FALSE; - return; - } - } - /* Invalidate the display filter in case it's in use */ if (dfilter_macro_uat && dfilter_macro_uat->post_update_cb) dfilter_macro_uat->post_update_cb(); @@ -591,7 +578,9 @@ static void* macro_copy(void* dest, const void* orig, size_t len _U_) { return d; } -static gboolean macro_name_chk(void* r _U_, const char* in_name, guint name_len, const void* u1 _U_, const void* u2 _U_, char** error) { +static gboolean macro_name_chk(void *mp, const char *in_name, guint name_len, + const void *u1 _U_, const void *u2 _U_, char **error) { + dfilter_macro_t* m = (dfilter_macro_t*)mp; guint i; if (name_len == 0) { @@ -606,6 +595,22 @@ static gboolean macro_name_chk(void* r _U_, const char* in_name, guint name_len, } } + /* When loading (!m->name) or when adding/changing the an item with a + * different name, check for uniqueness. NOTE: if a duplicate already + * exists (because the user manually edited the file), then this will + * not trigger a warning. */ + if (!m->name || !g_str_equal(m->name, in_name)) { + for (i = 0; i < num_macros; i++) { + /* This a string field which is always NUL-terminated, + * so no need to check name_len. */ + if (g_str_equal(in_name, macros[i].name)) { + *error = g_strdup_printf("macro '%s' already exists", + in_name); + return FALSE; + } + } + } + return TRUE; } |