diff mbox series

[BlueZ,v1,2/5] shared/shell: prevent integer overflow in bt_shell_init()

Message ID 20240704180752.94264-3-r.smirnov@omp.ru (mailing list archive)
State New, archived
Headers show
Series fix errors found by SVACE static analyzer #2 | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint success Gitlint PASS
tedd_an/IncrementalBuild fail [BlueZ,v1,2/5] shared/shell: prevent integer overflow in bt_shell_init() src/shared/shell.c: In function ‘bt_shell_init’: src/shared/shell.c:1336:21: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] 1336 | if (opt && index >= offset) { | ^~ cc1: all warnings being treated as errors make[1]: *** [Makefile:8680: src/shared/libshared_mainloop_la-shell.lo] Error 1 make[1]: *** Waiting for unfinished jobs.... make: *** [Makefile:4666: all] Error 2

Commit Message

Roman Smirnov July 4, 2024, 6:07 p.m. UTC
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 mbox series

Patch

diff --git a/src/shared/shell.c b/src/shared/shell.c
index add4fa131..ea0985815 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -1333,7 +1333,7 @@  void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
 				}
 			}
 
-			if (opt) {
+			if (opt && index >= offset) {
 				if (c != opt->options[index - offset].val) {
 					usage(argc, argv, opt);
 					exit(EXIT_SUCCESS);