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 (mailing list archive)
State Accepted
Commit 55f561a9cd0be9f939eaa6804b30fa67b3005002
Headers show
Series [BlueZ,v1] shared/shell: add a check for NULL in bt_shell_init() | 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/BuildEll success Build ELL PASS
tedd_an/BluezMake success Bluez Make PASS
tedd_an/MakeCheck success Bluez Make Check PASS
tedd_an/MakeDistcheck success Make Distcheck PASS
tedd_an/CheckValgrind success Check Valgrind PASS
tedd_an/CheckSmatch warning CheckSparse WARNING src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):
tedd_an/bluezmakeextell success Make External ELL PASS
tedd_an/IncrementalBuild success Incremental Build PASS
tedd_an/ScanBuild success Scan Build PASS

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!
bluez.test.bot@gmail.com July 1, 2024, 3:42 p.m. UTC | #2
This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=867152

---Test result---

Test Summary:
CheckPatch                    PASS      0.42 seconds
GitLint                       PASS      0.28 seconds
BuildEll                      PASS      25.26 seconds
BluezMake                     PASS      1808.72 seconds
MakeCheck                     PASS      13.37 seconds
MakeDistcheck                 PASS      183.37 seconds
CheckValgrind                 PASS      255.21 seconds
CheckSmatch                   WARNING   359.93 seconds
bluezmakeextell               PASS      121.69 seconds
IncrementalBuild              PASS      1522.89 seconds
ScanBuild                     PASS      997.55 seconds

Details
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):


---
Regards,
Linux Bluetooth
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;