diff mbox series

[Bluez,v1] lib: fix hci_strtolm crash

Message ID 20220214171329.Bluez.v1.1.I8c72b5af2506378bba6da369228ae50483231e35@changeid
State New
Headers show
Series [Bluez,v1] lib: fix hci_strtolm crash | expand

Commit Message

Howard Chung Feb. 14, 2022, 9:13 a.m. UTC
From: Yun-Hao Chung <howardchung@chromium.org>

|str| can be NULL in the case of reading lm value. Calling strcasestr
could lead to a crash.

Reviewed-by: Archie Pusaka <apusaka@chromium.org>
---
Verified by running "hciconfig hci0 lm" on hatch

 lib/hci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/hci.c b/lib/hci.c
index 5141f20ac..5228c2ad2 100644
--- a/lib/hci.c
+++ b/lib/hci.c
@@ -323,7 +323,7 @@  int hci_strtolm(char *str, unsigned int *val)
 	int ret = hci_str2bit(link_mode_map, str, val);
 
 	/* Deprecated name. Kept for compatibility. */
-	if (strcasestr(str, "MASTER")) {
+	if (!!str && strcasestr(str, "MASTER")) {
 		ret = 1;
 		*val |= HCI_LM_MASTER;
 	}