From f7b0f9b2d4a5894bbfd2c67fab42118de61fd525 Mon Sep 17 00:00:00 2001 From: Dario Lombardo Date: Sun, 10 Jan 2021 01:39:39 +0100 Subject: [PATCH] tshark: prevent multiple -T. Subsequent use of -T option infere to each other creating strange option combinations. Multiple -T are not supported, then prevent them. Fix: #17139. --- tshark.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tshark.c b/tshark.c index afaa92edd9..16897492d6 100644 --- a/tshark.c +++ b/tshark.c @@ -160,12 +160,13 @@ static gboolean epan_auto_reset = FALSE; * The way the packet decode is to be written. */ typedef enum { - WRITE_TEXT, /* summary or detail text */ - WRITE_XML, /* PDML or PSML */ - WRITE_FIELDS, /* User defined list of fields */ - WRITE_JSON, /* JSON */ - WRITE_JSON_RAW, /* JSON only raw hex */ - WRITE_EK /* JSON bulk insert to Elasticsearch */ + WRITE_NONE, /* dummy initial state */ + WRITE_TEXT, /* summary or detail text */ + WRITE_XML, /* PDML or PSML */ + WRITE_FIELDS, /* User defined list of fields */ + WRITE_JSON, /* JSON */ + WRITE_JSON_RAW, /* JSON only raw hex */ + WRITE_EK /* JSON bulk insert to Elasticsearch */ /* Add CSV and the like here */ } output_action_e; @@ -1309,6 +1310,12 @@ main(int argc, char *argv[]) separator = optarg; break; case 'T': /* printing Type */ + /* output_action has been already set. It means multiple -T. */ + if (output_action > WRITE_NONE) { + cmdarg_err("Multiple -T parameters are unsupported"); + exit_status = INVALID_OPTION; + goto clean_exit; + } print_packet_info = TRUE; if (strcmp(optarg, "text") == 0) { output_action = WRITE_TEXT; @@ -1488,6 +1495,10 @@ main(int argc, char *argv[]) } } + /* set the default output action to TEXT */ + if (output_action == WRITE_NONE) + output_action = WRITE_TEXT; + /* * Print packet summary information is the default if neither -V or -x * were specified. Note that this is new behavior, which allows for the @@ -4247,6 +4258,9 @@ print_packet(capture_file *cf, epan_dissect_t *edt) write_ek_proto_tree(output_fields, print_summary, print_hex, protocolfilter, protocolfilter_flags, edt, &cf->cinfo, stdout); return !ferror(stdout); + + default: + g_assert_not_reached(); } if (print_hex) {