diff mbox series

[BlueZ,v1] shared/shell: add a check for NULL in bt_shell_init()

Message ID 20240701134401.205121-1-r.smirnov@omp.ru
State New
Headers show
Series [BlueZ,v1] shared/shell: add a check for NULL in bt_shell_init() | expand

Commit Message

Roman Smirnov July 1, 2024, 1:44 p.m. UTC
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(-)

Comments

patchwork-bot+bluetooth@kernel.org July 1, 2024, 2:20 p.m. UTC | #1
Hello:

This patch was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Mon, 1 Jul 2024 16:44:01 +0300 you wrote:
> 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(-)

Here is the summary with links:
  - [BlueZ,v1] shared/shell: add a check for NULL in bt_shell_init()
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=55f561a9cd0b

You are awesome, thank you!
diff mbox series

Patch

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;