lib: fix hci_strtolm crash
authorYun-Hao Chung <howardchung@chromium.org>
Mon, 14 Feb 2022 09:13:43 +0000 (17:13 +0800)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:53 +0000 (14:55 +0530)
|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>
Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
lib/hci.c

index 66c30c1..8332997 100755 (executable)
--- a/lib/hci.c
+++ b/lib/hci.c
@@ -327,7 +327,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;
        }