Fix the crash in the MTU changed event 05/225705/1 accepted/tizen/unified/20200302.125819 submit/tizen/20200226.220348 submit/tizen/20200302.000010
authorDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 24 Feb 2020 05:29:17 +0000 (14:29 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 24 Feb 2020 05:31:02 +0000 (14:31 +0900)
Change-Id: I0b8d7c769b4845f592f5dc62066dd22af81c8120
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
src/bluetooth-common.c

index 9b22f145ae1bf9b238856c7f48b1a22a45de930f..78161ece787cc10c3dc2f0ea040ed2ce99160a52 100644 (file)
@@ -764,6 +764,8 @@ static void __bt_free_bt_device_sdp_info_s(bt_device_sdp_info_s *sdp_info)
 
 static int __bt_get_bt_gatt_client_att_mtu_info_s(bt_gatt_client_att_mtu_info_s **dest, bluetooth_le_att_mtu_info_t *source)
 {
+       BT_CHECK_INPUT_PARAMETER(source);
+
        *dest = (bt_gatt_client_att_mtu_info_s *)g_malloc0(sizeof(bt_gatt_client_att_mtu_info_s));
 
        if (_bt_convert_address_to_string(&((*dest)->remote_address), &(source->device_address)) != BT_ERROR_NONE) {
@@ -781,6 +783,8 @@ static int __bt_get_bt_gatt_client_att_mtu_info_s(bt_gatt_client_att_mtu_info_s
 
 static int __bt_get_bt_gatt_server_att_mtu_info_s(bt_gatt_server_att_mtu_info_s **dest, bluetooth_le_att_mtu_info_t *source)
 {
+       BT_CHECK_INPUT_PARAMETER(source);
+
        *dest = (bt_gatt_server_att_mtu_info_s *)g_malloc0(sizeof(bt_gatt_server_att_mtu_info_s));
 
        if (_bt_convert_address_to_string(&((*dest)->remote_address), &(source->device_address)) != BT_ERROR_NONE) {
@@ -3001,7 +3005,15 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                bt_gatt_client_s *client = NULL;
 
                BT_INFO("BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED");
-               __bt_get_bt_gatt_client_att_mtu_info_s(&mtu_info, (bluetooth_le_att_mtu_info_t *)(param->param_data));
+
+               if (__bt_get_bt_gatt_client_att_mtu_info_s(&mtu_info,
+                       (bluetooth_le_att_mtu_info_t *)(param->param_data)) != BT_ERROR_NONE) {
+                       BT_ERR("Fail to get MTU info");
+                       break;
+               }
+
+               if (mtu_info == NULL)
+                       break;
 
                client = _bt_gatt_get_client(mtu_info->remote_address);
 
@@ -3032,7 +3044,14 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
 
                server = (bt_gatt_server_s *)server_list->data;
 
-               __bt_get_bt_gatt_server_att_mtu_info_s(&mtu_info, (bluetooth_le_att_mtu_info_t *)(param->param_data));
+               if (__bt_get_bt_gatt_server_att_mtu_info_s(&mtu_info,
+                       (bluetooth_le_att_mtu_info_t *)(param->param_data)) != BT_ERROR_NONE) {
+                       BT_ERR("Fail to get MTU info");
+                       break;
+               }
+
+               if (mtu_info == NULL)
+                       break;
 
                if (server && server->att_mtu_changed_cb)
                        server->att_mtu_changed_cb(server,