Check the validity of fields given to tshark with "-e": complain and exit if

they aren't valid.

Should help avoid confusion like that in
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10201

Bug: 10201
Change-Id: Iff7f51ae042ca1a92d1c803b6cb61aa5d81ce205
Reviewed-on: https://code.wireshark.org/review/2654
Reviewed-by: Michael Mann <mmann78@netscape.net>
Reviewed-by: Evan Huus <eapache@gmail.com>
This commit is contained in:
Jeff Morriss 2014-06-25 15:37:36 -04:00 committed by Evan Huus
parent 4742fc8ed2
commit 9d4af5fccd
3 changed files with 35 additions and 0 deletions

View File

@ -1429,6 +1429,32 @@ void output_fields_add(output_fields_t *fields, const gchar *field)
}
static void
output_field_check(void *data, void *user_data)
{
gchar *field = (gchar *)data;
gboolean *all_valid = (gboolean *)user_data;
if (!strncmp(field, COLUMN_FIELD_FILTER, strlen(COLUMN_FIELD_FILTER)))
return;
if (!proto_registrar_get_byname(field)) {
g_warning("'%s' isn't a valid field!", field);
*all_valid = FALSE;
}
}
gboolean
output_fields_valid(output_fields_t *fields)
{
gboolean all_valid = TRUE;
g_ptr_array_foreach(fields->fields, output_field_check, &all_valid);
return all_valid;
}
gboolean output_fields_set_option(output_fields_t *info, gchar *option)
{
const gchar *option_name;

View File

@ -119,6 +119,7 @@ typedef struct _output_fields output_fields_t;
WS_DLL_PUBLIC output_fields_t* output_fields_new(void);
WS_DLL_PUBLIC void output_fields_free(output_fields_t* info);
WS_DLL_PUBLIC void output_fields_add(output_fields_t* info, const gchar* field);
WS_DLL_PUBLIC gboolean output_fields_valid(output_fields_t* info);
WS_DLL_PUBLIC gsize output_fields_num_fields(output_fields_t* info);
WS_DLL_PUBLIC gboolean output_fields_set_option(output_fields_t* info, gchar* option);
WS_DLL_PUBLIC void output_fields_list_options(FILE *fh);

View File

@ -1922,6 +1922,14 @@ main(int argc, char *argv[])
of the filter. We can now process all the "-z" arguments. */
start_requested_stats();
/* At this point MATE will have registered its field array so we can
check if the fields specified by the user are all good.
*/
if (!output_fields_valid(output_fields)) {
cmdarg_err("Some fields aren't valid");
return 1;
}
#ifdef HAVE_LIBPCAP
/* We currently don't support taps, or printing dissected packets,
if we're writing to a pipe. */