Allow zero length for GATT server write request 02/259002/1 accepted/tizen/unified/20210607.124357 submit/tizen/20210606.232858
authorDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 31 May 2021 01:11:21 +0000 (10:11 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 31 May 2021 01:11:21 +0000 (10:11 +0900)
Google's Chromecast app needs to response for zero
length write request in GATT server.

Change-Id: I5142ecd4dc7964caa2421aa0ecb39f0d0055c305
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
src/bluetooth-common.c

index cbed9bf..a8d38f3 100644 (file)
@@ -2778,17 +2778,20 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                void *user_data_write = NULL;
                bt_gatt_h gatt_handle = NULL;
                bt_gatt_h server = NULL;
+               char *val = NULL;
                bool is_own_handle = false;
                bluetooth_gatt_server_write_requested_info_t *write_req =
                                        (bluetooth_gatt_server_write_requested_info_t *)(param->param_data);
 
-               char *val = g_malloc0(write_req->length);
-               if (val == NULL) {
-                       BT_ERR("failed to allocate val");
-                       return;
-               }
+               if (write_req->length > 0) {
+                       val = g_malloc0(write_req->length);
+                       if (val == NULL) {
+                               BT_ERR("failed to allocate val");
+                               return;
+                       }
 
-               memcpy(val, write_req->data.data, write_req->length);
+                       memcpy(val, write_req->data.data, write_req->length);
+               }
                cb_wr = __bt_gatt_attribute_get_value_change_cb(write_req->attribute_handle,
                                                                &server, &gatt_handle, &is_own_handle, &user_data_write);