Fix weak point of scan filter logic 06/216206/1
authorDeokhyun Kim <dukan.kim@samsung.com>
Tue, 22 Oct 2019 08:29:20 +0000 (17:29 +0900)
committerDeokhyun Kim <dukan.kim@samsung.com>
Tue, 22 Oct 2019 08:29:20 +0000 (17:29 +0900)
Change-Id: I02138cc41598cef11544ea7edf9c8d0230074a8f
Signed-off-by: Deokhyun Kim <dukan.kim@samsung.com>
src/adapter.c

index 31ad0e6..461bb77 100644 (file)
@@ -4596,11 +4596,11 @@ static DBusMessage *adapter_le_scan_filter_add_remove(DBusConnection *conn,
        struct btd_device *dev = NULL;
        dbus_int32_t client_if, action, filt_type, filt_index;
        dbus_int32_t company_id, company_id_mask;
-       gchar *address = NULL;
+       gchar *str = NULL;
        dbus_uint32_t address_type = 0;
-       uint8_t addr_type;
+       uint8_t addr_type = 0;
        GSList *list;
-       char ida_string[18];
+       char string[30];
        uint8_t *p_uuid, *p_uuid_mask, *p_data, *p_mask;
        int32_t uuid_len = 0, uuid_mask_len = 0, data_len = 0, mask_len = 0;
        gboolean err;
@@ -4632,45 +4632,49 @@ static DBusMessage *adapter_le_scan_filter_add_remove(DBusConnection *conn,
                                                DBUS_TYPE_INT32, &company_id_mask,
                                                DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &p_uuid, &uuid_len,
                                                DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &p_uuid_mask, &uuid_mask_len,
-                                               DBUS_TYPE_STRING, &address,
+                                               DBUS_TYPE_STRING, &str,
                                                DBUS_TYPE_UINT32, &address_type,
                                                DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &p_data, &data_len,
                                                DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &p_mask, &mask_len,
                                                DBUS_TYPE_INVALID))
                return btd_error_invalid_args(msg);
 
-       list = g_slist_find_custom(adapter->devices, address, device_rpa_cmp);
-       if (!list)
-               list = g_slist_find_custom(adapter->devices, address,
-                                                       device_address_cmp);
-       if (list)
-               dev = list->data;
-       if (dev && device_get_rpa_exist(dev) == true) {
-               ba2str(device_get_address(dev), ida_string);
-               if (btd_device_get_bdaddr_type(dev) == BDADDR_LE_PUBLIC)
+       if (filt_type == TYPE_DEVICE_ADDRESS) {
+               list = g_slist_find_custom(adapter->devices, str, device_rpa_cmp);
+               if (!list)
+                       list = g_slist_find_custom(adapter->devices, str,
+                                                               device_address_cmp);
+               if (list)
+                       dev = list->data;
+               if (dev && device_get_rpa_exist(dev) == true) {
+                       ba2str(device_get_address(dev), string);
+                       if (btd_device_get_bdaddr_type(dev) == BDADDR_LE_PUBLIC)
+                               addr_type = 0x00;
+                       else
+                               addr_type = 0x01;
+               } else {
+                       strncpy(string, str, sizeof(string));
                        addr_type = 0x00;
-               else
-                       addr_type = 0x01;
+               }
+
+               DBG("addr %s, type %d", string, addr_type);
        } else {
-               memcpy(ida_string, address, sizeof(ida_string));
-               addr_type = 0x00;
+               strncpy(string, str, sizeof(string));
        }
 
-       DBG("addr %s, type %d", ida_string, addr_type);
-
 #ifdef TIZEN_FEATURE_PLATFROM_SCAN_FILTER
        if (ctlr_filter_support)
 #endif
        err = adapter_le_set_scan_filter_data(client_if, action, filt_type,
                        filt_index, company_id, company_id_mask,
                        uuid_len, p_uuid, uuid_mask_len, p_uuid_mask,
-                       ida_string, addr_type, data_len, p_data, mask_len, p_mask);
+                       string, addr_type, data_len, p_data, mask_len, p_mask);
 #ifdef TIZEN_FEATURE_PLATFROM_SCAN_FILTER
        else
                err = adapter_le_set_platform_scan_filter_data(adapter, client_if, action, filt_type,
                                filt_index, company_id, company_id_mask,
                                uuid_len, p_uuid, uuid_mask_len, p_uuid_mask,
-                               ida_string, addr_type, data_len, p_data, mask_len, p_mask);
+                               string, addr_type, data_len, p_data, mask_len, p_mask);
 #endif
        if (!err)
                return btd_error_failed(msg, "Failed to add/remove filter");