NULL assertion in g_ascii_strcasecmp 71/151571/1
authorAbhishek Chandra <abhishek.ch@samsung.com>
Thu, 21 Sep 2017 05:21:15 +0000 (10:51 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 21 Sep 2017 07:43:26 +0000 (16:43 +0900)
[Problem]Seeker remote address is resetted to
NULL if GATT connect is failed ,which causes
seeker object to remain in the Seeker list and
can never be destroyed as remote address is null .
Next time ,while finding seeker .
g_ascii_strcasecmp is called with NULL remote address,
causing it to assert.

[Causes & Measure] Removed remote address setting
to NULL and guarded code in case of NULL being
passed to strcmp.

[Checking Method] UT

Change-Id: I04c475c9316ac04437d3ea0bc096e3da346ba421
Signed-off-by: Abhishek Chandra <abhishek.ch@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
src/bluetooth-gatt.c
src/bluetooth-otp.c
src/bluetooth-proximity.c
src/bluetooth-tds.c

index 04d508eea2c7b4bc305c30f877d646fa0e39ed49..b05bf207a42987d034ad0186c1754857c29b5783 100644 (file)
@@ -80,7 +80,11 @@ static int __get_gatt_handle_by_uuid(GSList *list, const char *uuid,
                bt_gatt_common_s *common = (bt_gatt_common_s *)l->data;
 
                uuid128_b = _bt_convert_uuid_to_uuid128(common->uuid);
-               if (g_ascii_strcasecmp(uuid128_a, uuid128_b) == 0) {
+
+               if (uuid128_b == NULL) {
+                       BT_ERR("__get_gatt_handle_by_uuid Error Parameter are NULL..\n");
+                       continue;
+               } else if (g_ascii_strcasecmp(uuid128_a, uuid128_b) == 0) {
                        g_free(uuid128_b);
                        break;
                }
@@ -2773,7 +2777,10 @@ int bt_gatt_client_create(const char *remote_address, bt_gatt_client_h *client)
        for (l = gatt_client_list; l; l = g_slist_next(l)) {
                bt_gatt_client_s *c = (bt_gatt_client_s *)l->data;
 
-               if (!g_ascii_strcasecmp(c->remote_address, remote_address)) {
+               if ((c == NULL) || (c->remote_address == NULL)) {
+                       BT_ERR("bt_gatt_client_create Error Parameter are NULL..\n");
+                       continue;
+               } else if (!g_ascii_strcasecmp(c->remote_address, remote_address)) {
                        BT_ERR("Gatt client for %s is already created",
                                        remote_address);
                        return BT_ERROR_ALREADY_DONE;
@@ -3134,7 +3141,11 @@ static void __value_changed_cb(char *char_path,
                svc = (bt_gatt_service_s *)l->data;
                for (ll = svc->characteristics; ll; ll = g_slist_next(ll)) {
                        chr = (bt_gatt_characteristic_s *)ll->data;
-                       if (g_ascii_strcasecmp(chr->path, char_path) == 0) {
+
+                       if ((chr == NULL) || (chr->path == NULL)) {
+                               BT_ERR("__value_changed_cb Error Parameter are NULL..\n");
+                               continue;
+                       } else if (g_ascii_strcasecmp(chr->path, char_path) == 0) {
                                if (chr->value_changed_cb)
                                        chr->value_changed_cb(chr, value,
                                                value_length,
index 7a5328a61fff03d1d7cf84e3bef20e186ef044b9..4fa02f086b4cb12e41deae625e26ec43f314e564 100644 (file)
@@ -350,9 +350,12 @@ static bt_otp_client_s *_bt_otp_client_find(const char *remote_address)
 
        for (l = otp_client_list; l; l = g_slist_next(l)) {
                info = l->data;
-
-               if (info && !g_ascii_strcasecmp(info->remote_address, remote_address))
+               if ((info == NULL) || (info->remote_address == NULL)) {
+                       BT_ERR("_bt_otp_client_find Error Parameter are NULL..\n");
+                       continue;
+               } else if (info && !g_ascii_strcasecmp(info->remote_address, remote_address)) {
                        return info;
+               }
        }
        return NULL;
 }
@@ -807,7 +810,10 @@ int bt_otp_client_create(const char *remote_address, bt_otp_client_h *otp_client
        for (l = otp_client_list; l; l = g_slist_next(l)) {
                info = l->data;
 
-               if (info && !g_ascii_strcasecmp(info->remote_address, remote_address)) {
+               if ((info == NULL) || (info->remote_address == NULL)) {
+                       BT_ERR("bt_otp_client_create Error Parameter are NULL..\n");
+                       continue;
+               } else if (info && !g_ascii_strcasecmp(info->remote_address, remote_address)) {
                        BT_ERR("OTP Client for Remote device [%s] is already created",
                                        remote_address);
                        *otp_client = (bt_otp_client_h)info;
index 799337d9dfb3ebb49c2e7f8f38dac57a3ae29a8e..6ca39901c4c0c5136e0251bc0ecdecb395c219b6 100644 (file)
@@ -160,8 +160,12 @@ static bt_proximity_monitor_s *_bt_proximity_monitor_find(const char *remote_add
        for (l = proximity_monitor_list; l; l = g_slist_next(l)) {
                bt_proximity_monitor_s *c = (bt_proximity_monitor_s *)l->data;
 
-               if (!g_ascii_strcasecmp(c->remote_address, remote_address))
+               if ((c == NULL) || (c->remote_address == NULL)) {
+                       BT_ERR("_bt_proximity_monitor_find Error Parameter are NULL..\n");
+                       continue;
+               } else if (!g_ascii_strcasecmp(c->remote_address, remote_address)) {
                        return c;
+               }
        }
        return NULL;
 }
@@ -220,7 +224,10 @@ int bt_proximity_monitor_create(const char *remote_address, bt_proximity_monitor
        for (l = proximity_monitor_list; l; l = g_slist_next(l)) {
                bt_proximity_monitor_s *c = (bt_proximity_monitor_s *)l->data;
 
-               if (!g_ascii_strcasecmp(c->remote_address, remote_address)) {
+               if ((c == NULL) || (c->remote_address == NULL)) {
+                       BT_ERR("bt_proximity_monitor_create Error Parameter are NULL..\n");
+                       continue;
+               } else if (!g_ascii_strcasecmp(c->remote_address, remote_address)) {
                        BT_ERR("Gatt client for %s is already created",
                                        remote_address);
                        return BT_ERROR_ALREADY_DONE;
index 5bade3c7784f8dbd7aee3f4202826bba06991b1f..63ff05fb1fdb8aa7d03d9655107066532be7b7c1 100644 (file)
@@ -346,8 +346,12 @@ static bt_tds_seeker_s *_bt_tds_seeker_find(const char *remote_address)
 
        for (l = tds_seeker_list; l; l = g_slist_next(l)) {
 
-               if (!g_ascii_strcasecmp(((bt_tds_seeker_s *)l->data)->remote_address, remote_address))
+               if ((l == NULL) || (l->data == NULL) || (((bt_tds_seeker_s *)l->data)->remote_address == NULL)) {
+                       BT_ERR("_bt_tds_seeker_find Error Parameter are NULL..\n");
+                       continue;
+               } else if (!g_ascii_strcasecmp(((bt_tds_seeker_s *)l->data)->remote_address, remote_address)) {
                        return ((bt_tds_seeker_s *)l->data);
+               }
        }
        return NULL;
 }
@@ -641,8 +645,6 @@ int _bt_tds_parse_transport_blocks(bt_tds_transport_block_list_s **info,
 
 static void __bt_tds_reset_seeker_data(bt_tds_seeker_s *seeker)
 {
-       g_free((seeker)->remote_address);
-       (seeker)->remote_address = NULL;
 
        g_free((seeker)->tds_control_point);
        (seeker)->tds_control_point = NULL;
@@ -1040,7 +1042,10 @@ int bt_tds_seeker_create(const char *remote_address, bt_tds_seeker_h *seeker)
        for (l = tds_seeker_list; l; l = g_slist_next(l)) {
                bt_tds_seeker_s *c = (bt_tds_seeker_s *)l->data;
 
-               if (!g_ascii_strcasecmp(c->remote_address, remote_address)) {
+               if ((c == NULL) || ((c->remote_address == NULL))) {
+                       BT_ERR("bt_tds_seeker_create Error Parameter are NULL..\n");
+                       continue;
+               } else if (!g_ascii_strcasecmp(c->remote_address, remote_address)) {
                        BT_ERR("TDS Seeker for Remote Provider [%s] is already created",
                                        remote_address);
                        *seeker = (bt_tds_seeker_h)c;