diff mbox series

[BlueZ,v2,05/20] client/main: Fix array access

Message ID 20240510121355.3241456-6-hadess@hadess.net (mailing list archive)
State Accepted
Commit f3f762b77b5898ac0203d00bd64087e2a22e34be
Headers show
Series Fix a number of static analysis issues | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint fail WARNING: I3 - ignore-body-lines: gitlint will be switching from using Python regex 'match' (match beginning) to 'search' (match anywhere) semantics. Please review your ignore-body-lines.regex option accordingly. To remove this warning, set general.regex-style-search=True. More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search 4: B1 Line exceeds max length (134>80): "bluez-5.75/client/main.c:833: error[ctuArrayIndex]: Array index out of bounds; 'argv' buffer size is 0 and it is accessed at offset 1." 5: B3 Line contains hard tab characters (\t): "831| const char **opt;" 7: B3 Line contains hard tab characters (\t): "833|-> if (!strcmp(argv[1], "help")) {" 8: B3 Line contains hard tab characters (\t): "834| for (opt = arg_table; opt && *opt; opt++)" 9: B3 Line contains hard tab characters (\t): "835| bt_shell_printf("%s\n", *opt);"
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Bastien Nocera May 10, 2024, 12:10 p.m. UTC
Error: CPPCHECK_WARNING (CWE-788): [#def36]
bluez-5.75/client/main.c:833: error[ctuArrayIndex]: Array index out of bounds; 'argv' buffer size is 0 and it is accessed at offset 1.
831|	const char **opt;
832|
833|->	if (!strcmp(argv[1], "help")) {
834|		for (opt = arg_table; opt && *opt; opt++)
835|			bt_shell_printf("%s\n", *opt);
---
 client/main.c | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/client/main.c b/client/main.c
index 51d08a67aa1a..f703cc91b24a 100644
--- a/client/main.c
+++ b/client/main.c
@@ -830,6 +830,11 @@  static gboolean parse_argument(int argc, char *argv[], const char **arg_table,
 {
 	const char **opt;
 
+	if (argc < 2) {
+		bt_shell_printf("Missing argument to %s\n", argv[0]);
+		return FALSE;
+	}
+
 	if (!strcmp(argv[1], "help")) {
 		for (opt = arg_table; opt && *opt; opt++)
 			bt_shell_printf("%s\n", *opt);