From c47a705beb4d03d1a7498802047f6410814dced3 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Tue, 7 Jan 2020 18:09:46 -0500 Subject: [PATCH] track-untrack.c: error out on unknown CLI options MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Issue ===== At the moment, it's possible to have unknown options in the `track` and `untrack` commands. They are silently ignored. For example, the following command line is accepted without problem: lttng untrack HELLO -k --all --pid This was witnessed in the `test_event_tracker` tests. The `lttng_track()` and `lttng_untrack() functions in `tests/utils/util.sh` are currently passing the `$1` bash variable of the function to the `track` and `untrack` througth their "$@" variable. The commands should not silently accept those unknown options. Fix === 1. After looping on all the known options, check if there is any leftover options and error out if it's the case. 2. Fix the `utils.sh` functions to that they don't pass the `$1` variable to the commands. Signed-off-by: Francis Deslauriers Change-Id: I822ba09c8ce1ffa8366c586e760a9257e8078e43 Signed-off-by: Jérémie Galarneau --- src/bin/lttng/commands/track-untrack.c | 8 ++++++++ tests/utils/utils.sh | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/bin/lttng/commands/track-untrack.c b/src/bin/lttng/commands/track-untrack.c index 0d7169729..afb4d93d1 100644 --- a/src/bin/lttng/commands/track-untrack.c +++ b/src/bin/lttng/commands/track-untrack.c @@ -594,6 +594,7 @@ int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str, enum cmd_error_code command_ret = CMD_SUCCESS; static poptContext pc; char *session_name = NULL; + const char *leftover = NULL; struct mi_writer *writer = NULL; if (argc < 1) { @@ -715,6 +716,13 @@ int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str, session_name = opt_session_name; } + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + goto end; + } + /* Mi check */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index 1b2f71f18..b2c08680e 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -1469,6 +1469,7 @@ function lttng_load_fail() function lttng_track() { local expected_to_fail="$1" + shift 1 local opts="$@" $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST ret=$? @@ -1493,6 +1494,7 @@ function lttng_track_fail() function lttng_untrack() { local expected_to_fail="$1" + shift 1 local opts="$@" $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST ret=$? -- 2.34.1