diff mbox series

[BlueZ,v1,resend,1/3] tools/rctest: add NULL checks to main()

Message ID 20240809162252.50098-2-r.smirnov@omp.ru (mailing list archive)
State Accepted
Commit b752f760da474c53d66cc4b137db0838aee3c953
Headers show
Series fix errors found by SVACE static analyzer #4 | 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 tools/rctest.c:627:33: warning: non-ANSI function declaration of function 'automated_send_recv'android/avctp.c:505:34: warning: Variable length array is used.android/avctp.c:556:34: warning: Variable length array is used.
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 Aug. 9, 2024, 4:22 p.m. UTC
It is necessary to prevent dereferencing of a NULL pointer.

Found with the SVACE static analysis tool.
---
 tools/rctest.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

Comments

bluez.test.bot@gmail.com Aug. 9, 2024, 7 p.m. UTC | #1
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=878285

---Test result---

Test Summary:
CheckPatch                    PASS      1.39 seconds
GitLint                       PASS      0.97 seconds
BuildEll                      PASS      24.54 seconds
BluezMake                     PASS      1717.48 seconds
MakeCheck                     PASS      13.68 seconds
MakeDistcheck                 PASS      176.56 seconds
CheckValgrind                 PASS      250.57 seconds
CheckSmatch                   WARNING   353.99 seconds
bluezmakeextell               PASS      121.69 seconds
IncrementalBuild              PASS      4675.93 seconds
ScanBuild                     PASS      991.93 seconds

Details
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
tools/rctest.c:627:33: warning: non-ANSI function declaration of function 'automated_send_recv'android/avctp.c:505:34: warning: Variable length array is used.android/avctp.c:556:34: warning: Variable length array is used.


---
Regards,
Linux Bluetooth
diff mbox series

Patch

diff --git a/tools/rctest.c b/tools/rctest.c
index b72be917c..367e41e3c 100644
--- a/tools/rctest.c
+++ b/tools/rctest.c
@@ -742,6 +742,9 @@  int main(int argc, char *argv[])
 			break;
 
 		case 'a':
+			if (!optarg)
+				break;
+
 			mode = AUTO;
 
 			if (!strncasecmp(optarg, "hci", 3))
@@ -756,6 +759,9 @@  int main(int argc, char *argv[])
 			break;
 
 		case 'i':
+			if (!optarg)
+				break;
+
 			if (!strncasecmp(optarg, "hci", 3))
 				hci_devba(atoi(optarg + 3), &bdaddr);
 			else
@@ -763,10 +769,14 @@  int main(int argc, char *argv[])
 			break;
 
 		case 'P':
-			channel = atoi(optarg);
+			if (optarg)
+				channel = atoi(optarg);
 			break;
 
 		case 'U':
+			if (!optarg)
+				break;
+
 			if (!strcasecmp(optarg, "spp"))
 				uuid = SERIAL_PORT_SVCLASS_ID;
 			else if (!strncasecmp(optarg, "0x", 2))
@@ -792,11 +802,13 @@  int main(int argc, char *argv[])
 			break;
 
 		case 'L':
-			linger = atoi(optarg);
+			if (optarg)
+				linger = atoi(optarg);
 			break;
 
 		case 'W':
-			defer_setup = atoi(optarg);
+			if (optarg)
+				defer_setup = atoi(optarg);
 			break;
 
 		case 'B':
@@ -808,19 +820,23 @@  int main(int argc, char *argv[])
 			break;
 
 		case 'N':
-			num_frames = atoi(optarg);
+			if (optarg)
+				num_frames = atoi(optarg);
 			break;
 
 		case 'C':
-			count = atoi(optarg);
+			if (optarg)
+				count = atoi(optarg);
 			break;
 
 		case 'D':
-			delay = atoi(optarg) * 1000;
+			if (optarg)
+				delay = atoi(optarg) * 1000;
 			break;
 
 		case 'Y':
-			priority = atoi(optarg);
+			if (optarg)
+				priority = atoi(optarg);
 			break;
 
 		case 'T':