From 475fc9174622bce9c3d6589ebbb2952b4e9d4720 Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Fri, 23 Aug 2024 15:40:05 +0800 Subject: [PATCH] shell: modules: kernel: add additional check in unwind cmd Use `shell_strtoull()` to parse the thread ID argument for error checking. Signed-off-by: Yong Cong Sin Signed-off-by: Yong Cong Sin --- subsys/shell/modules/kernel_service.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/subsys/shell/modules/kernel_service.c b/subsys/shell/modules/kernel_service.c index 44393c83794..7e23dcfafb2 100644 --- a/subsys/shell/modules/kernel_service.c +++ b/subsys/shell/modules/kernel_service.c @@ -324,11 +324,16 @@ static bool print_trace_address(void *arg, unsigned long ra) static int cmd_kernel_thread_unwind(const struct shell *sh, size_t argc, char **argv) { struct k_thread *thread; + int err = 0; if (argc == 1) { thread = _current; } else { - thread = UINT_TO_POINTER(strtoll(argv[1], NULL, 16)); + thread = UINT_TO_POINTER(shell_strtoull(argv[1], 16, &err)); + if (err != 0) { + shell_error(sh, "Unable to parse thread ID %s (err %d)", argv[1], err); + return err; + } if (!thread_is_valid(thread)) { shell_error(sh, "Invalid thread id %p", (void *)thread);