From 503c878a4072f6c2a5a589fa66f0eee8f6601c37 Mon Sep 17 00:00:00 2001 From: Abhay agarwal Date: Tue, 6 Aug 2019 15:20:31 +0530 Subject: [PATCH] Fix ble payload NULL issue Change-Id: If2b186cfeea63fb9a0ebae5cffb5f6bbfa548074 Signed-off-by: Abhay agarwal --- ua-daemon/src/pm/ua-pm-util.c | 5 +++-- ua-daemon/src/ua-manager-core.c | 20 ++++++++++++++------ ua-daemon/src/ua-manager-device-db.c | 18 ++++++++++-------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/ua-daemon/src/pm/ua-pm-util.c b/ua-daemon/src/pm/ua-pm-util.c index 85638a3..e4a1a57 100644 --- a/ua-daemon/src/pm/ua-pm-util.c +++ b/ua-daemon/src/pm/ua-pm-util.c @@ -277,8 +277,9 @@ uam_device_info_s *_pm_util_uas_dev_info_to_uam_dev_info(const uas_device_info_t device->discriminant = dev->discriminant; g_strlcpy(device->device_id, dev->device_id, UAM_DEVICE_ID_MAX_STRING_LEN); - device->payload[UAM_BLE_PAYLOAD_STRING_LEN] = 0; - memcpy(device->payload, dev->payload, UAM_BLE_PAYLOAD_STRING_LEN); + memset(device->payload, 0, UAM_BLE_PAYLOAD_STRING_LEN + 1); + if (dev->payload) + memcpy(device->payload, dev->payload, UAM_BLE_PAYLOAD_STRING_LEN); for (i = 0; i < dev->num_addr; i++) { UAM_DBG("Address[%d]: %s", i, dev->addr_list[i].address); diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index ef2da56..8046840 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -408,6 +408,7 @@ static void __get_uam_db_dev_list_to_uam_dev_list( (*count)++; } } + UAM_INFO("Count = %d", *count); *device_list = g_new0(uam_device_info_s, *count); @@ -456,11 +457,16 @@ static void __get_uam_db_dev_list_to_uam_dev_list( UAM_DEVICE_ID_MAX_STRING_LEN); (*device_list)[indx].payload[UAM_BLE_PAYLOAD_STRING_LEN] = 0; - memcpy((*device_list)[indx].payload, tech->payload, + if (tech->payload) + memcpy((*device_list)[indx].payload, tech->payload, UAM_BLE_PAYLOAD_STRING_LEN); (*device_list)[indx].discriminant = tech->discriminant; (*device_list)[indx].last_seen = tech->timestamp; (*device_list)[indx++].type = tech->tech_type; + UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%s", (*device_list)[indx-1].device_id, + (*device_list)[indx-1].type, (*device_list)[indx-1].mac, (*device_list)[indx-1].ipv4_addr, + (*device_list)[indx-1].last_seen, (*device_list)[indx-1].operating_system, + (*device_list)[indx-1].discriminant, (*device_list)[indx-1].payload); } } @@ -505,9 +511,9 @@ static int __copy_tech_info_to_device_info(uam_db_tech_info_t *tech, uam_device_ UAM_DEVICE_ID_MAX_STRING_LEN); device->type = tech->tech_type; device->discriminant = tech->discriminant; - - device->payload[UAM_BLE_PAYLOAD_STRING_LEN] = 0; - memcpy(device->payload, tech->payload, + memset(device->payload, 0, UAM_BLE_PAYLOAD_STRING_LEN + 1); + if (tech->payload) + memcpy(device->payload, tech->payload, UAM_BLE_PAYLOAD_STRING_LEN); FUNC_EXIT; @@ -3097,8 +3103,10 @@ static void __get_service_dev_list( UAM_DEVICE_ID_MAX_STRING_LEN); (*device_list)[indx].last_seen = tech->timestamp; (*device_list)[indx].discriminant = tech->discriminant; - (*device_list)[indx].payload[UAM_BLE_PAYLOAD_STRING_LEN] = 0; - memcpy((*device_list)[indx].payload, tech->payload, + memset((*device_list)[indx].payload, 0, + UAM_BLE_PAYLOAD_STRING_LEN); + if (tech->payload) + memcpy((*device_list)[indx].payload, tech->payload, UAM_BLE_PAYLOAD_STRING_LEN); (*device_list)[indx++].type = tech->tech_type; } diff --git a/ua-daemon/src/ua-manager-device-db.c b/ua-daemon/src/ua-manager-device-db.c index 45ad9bb..30c519d 100644 --- a/ua-daemon/src/ua-manager-device-db.c +++ b/ua-daemon/src/ua-manager-device-db.c @@ -574,9 +574,10 @@ int _ua_device_db_get_device(char *device_id, int tech_type, char *address, info->dev_info.operating_system = sqlite3_column_int(stmt, 6); info->user_id = sqlite3_column_int(stmt, 7); info->dev_info.discriminant = sqlite3_column_int(stmt, 8); - info->dev_info.payload[UAM_BLE_PAYLOAD_STRING_LEN] = 0; - memcpy(info->dev_info.payload, (char *)sqlite3_column_text(stmt, 9), - UAM_BLE_PAYLOAD_STRING_LEN); + memset(info->dev_info.payload, 0, UAM_BLE_PAYLOAD_STRING_LEN + 1); + if ((char*)sqlite3_column_text(stmt, 9)) + memcpy(info->dev_info.payload, (char *)sqlite3_column_text(stmt, 9), + UAM_BLE_PAYLOAD_STRING_LEN); UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d-%d-%s", info->dev_info.device_id, @@ -587,7 +588,7 @@ int _ua_device_db_get_device(char *device_id, int tech_type, char *address, info->presence_state, info->dev_info.operating_system, info->user_id, - info->dev_info.discriminant); + info->dev_info.discriminant, info->dev_info.payload); } @@ -669,9 +670,10 @@ GSList *_ua_device_db_get_all_devices(void) info->dev_info.operating_system = sqlite3_column_int(stmt, 6); info->user_id = sqlite3_column_int(stmt, 7); info->dev_info.discriminant = sqlite3_column_int(stmt, 8); - info->dev_info.payload[UAM_BLE_PAYLOAD_STRING_LEN] = 0; - memcpy(info->dev_info.payload, (char *)sqlite3_column_text(stmt, 9), - UAM_BLE_PAYLOAD_STRING_LEN); + memset(info->dev_info.payload, 0, UAM_BLE_PAYLOAD_STRING_LEN + 1); + if ((char*)sqlite3_column_text(stmt, 9)) + memcpy(info->dev_info.payload, (char *)sqlite3_column_text(stmt, 9), + UAM_BLE_PAYLOAD_STRING_LEN); UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d-%d-%s", info->dev_info.device_id, @@ -682,7 +684,7 @@ GSList *_ua_device_db_get_all_devices(void) info->presence_state, info->dev_info.operating_system, info->user_id, - info->dev_info.discriminant); + info->dev_info.discriminant, info->dev_info.payload); device_list = g_slist_append(device_list, info); -- 2.7.4