From 0e43bcbfbc967868b8b939e378268d6296011886 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 29 Oct 2020 11:43:35 -0400 Subject: [PATCH] Clean-up: sessiond: silence negative index warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Coverity warns that `lttng_action_get_type()` can return a negative index (LTTNG_ACTION_TYPE_UNKNOWN). This scenario is not reachable, but a check is added to silence the analyzer. Original report: 1435955 Negative array index read A memory location at a negative offset from the beginning of the array will be read, resulting in incorrect values. In get_action_name: Negative value used to index an array in a read operation (CWE-129) Reported-by: Coverity Scan Signed-off-by: Jérémie Galarneau Change-Id: I5952096a1d29f0d4a3c4350a2a842874d5f3973b --- src/bin/lttng-sessiond/action-executor.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/bin/lttng-sessiond/action-executor.c b/src/bin/lttng-sessiond/action-executor.c index ca9690743..db16f8049 100644 --- a/src/bin/lttng-sessiond/action-executor.c +++ b/src/bin/lttng-sessiond/action-executor.c @@ -104,7 +104,11 @@ static const char *action_type_names[] = { static const char *get_action_name(const struct lttng_action *action) { - return action_type_names[lttng_action_get_type(action)]; + const enum lttng_action_type action_type = lttng_action_get_type(action); + + assert(action_type != LTTNG_ACTION_TYPE_UNKNOWN); + + return action_type_names[action_type]; } /* Check if this trigger allowed to interect with a given session. */ @@ -480,12 +484,16 @@ static int action_executor_generic_handler(struct action_executor *executor, const struct action_work_item *work_item, const struct lttng_action *action) { + const enum lttng_action_type action_type = lttng_action_get_type(action); + + assert(action_type != LTTNG_ACTION_TYPE_UNKNOWN); + DBG("Executing action `%s` of trigger `%p` action work item %" PRIu64, get_action_name(action), work_item->trigger, work_item->id); - return action_executors[lttng_action_get_type(action)]( + return action_executors[action_type]( executor, work_item, action); } -- 2.34.1