All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ v1] shared/shell: add a check for NULL in bt_shell_init()
@ 2024-07-01 13:44 Roman Smirnov
  2024-07-01 14:20 ` patchwork-bot+bluetooth
  2024-07-01 15:42 ` [BlueZ,v1] " bluez.test.bot
  0 siblings, 2 replies; 3+ messages in thread
From: Roman Smirnov @ 2024-07-01 13:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Roman Smirnov

The opt variable is checked for NULL at the beginning of
the function. It is necessary to add a check to prevent null
pointer dereferencing.

Found with the SVACE static analysis tool.
---
 src/shared/shell.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index f3f7bab9a..2ecc41bf3 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -1328,13 +1328,15 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
 				}
 			}
 
-			if (c != opt->options[index - offset].val) {
-				usage(argc, argv, opt);
-				exit(EXIT_SUCCESS);
-				return;
-			}
+			if (opt) {
+				if (c != opt->options[index - offset].val) {
+					usage(argc, argv, opt);
+					exit(EXIT_SUCCESS);
+					return;
+				}
 
-			*opt->optarg[index - offset] = optarg ? : "";
+				*opt->optarg[index - offset] = optarg ? : "";
+			}
 		}
 
 		index = -1;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-07-01 15:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-01 13:44 [PATCH BlueZ v1] shared/shell: add a check for NULL in bt_shell_init() Roman Smirnov
2024-07-01 14:20 ` patchwork-bot+bluetooth
2024-07-01 15:42 ` [BlueZ,v1] " bluez.test.bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.