From 85d98aecd6a9504cb51a4bd4f8b37cc11a0057f8 Mon Sep 17 00:00:00 2001 From: Roman Smirnov Date: Fri, 5 Jul 2024 10:57:04 +0300 Subject: [PATCH] shared/shell: prevent integer overflow in bt_shell_init() An integer overflow will occur if index < offest. It is necessary to prevent this case. Found with the SVACE static analysis tool. --- src/shared/shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/shell.c b/src/shared/shell.c index 73caa77ce..88ecaa076 100644 --- a/src/shared/shell.c +++ b/src/shared/shell.c @@ -1334,7 +1334,7 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt) } } - if (opt) { + if (opt && index >= 0 && (size_t)index >= offset) { if (c != opt->options[index - offset].val) { usage(argc, argv, opt); exit(EXIT_SUCCESS); -- 2.47.3