From 476d199752f90457ff0920fad5051f4b12b0c427 Mon Sep 17 00:00:00 2001 From: Alexej Rempel Date: Fri, 18 Mar 2022 14:30:04 +0100 Subject: [PATCH] logging: shell: fix shell stats null pointer dereference If CONFIG_SHELL_STATS is disabled, shell->stats is NULL and must not be dereferenced. Guard against it. Fixes #44089 Signed-off-by: Alexej Rempel --- subsys/shell/shell_log_backend.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subsys/shell/shell_log_backend.c b/subsys/shell/shell_log_backend.c index 37d39c01153..364839bab67 100644 --- a/subsys/shell/shell_log_backend.c +++ b/subsys/shell/shell_log_backend.c @@ -320,7 +320,9 @@ static void dropped(const struct log_backend *const backend, uint32_t cnt) const struct shell *shell = (const struct shell *)backend->cb->ctx; const struct shell_log_backend *log_backend = shell->log_backend; - atomic_add(&shell->stats->log_lost_cnt, cnt); + if (IS_ENABLED(CONFIG_SHELL_STATS)) { + atomic_add(&shell->stats->log_lost_cnt, cnt); + } atomic_add(&log_backend->control_block->dropped_cnt, cnt); }