From 918a29499ca381c2be9ca63f4975693d2458d31f Mon Sep 17 00:00:00 2001 From: "saerome.kim" Date: Wed, 8 Aug 2018 11:51:35 +0900 Subject: [PATCH] Fixed Coverity issue : 1013549, 1013553, 1013556, 1013557, 1013560, 1013562, 1013563, 1013566 Change-Id: Ib351e1fa147236c83d83a1bda484d6b072bf8d02 Signed-off-by: saerome.kim --- common/zb-utils.c | 2 +- src/zbl-zcl.c | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/common/zb-utils.c b/common/zb-utils.c index 6a8ac07..980d95c 100644 --- a/common/zb-utils.c +++ b/common/zb-utils.c @@ -339,7 +339,7 @@ int zb_zcl_get_data_size(zb_zcl_data_type_e type) if (attribute_sizes[i].type == type) return attribute_sizes[i].size; } - return -1; + return 0; } const char* zb_zcl_get_data_type_str(zb_zcl_data_type_e type) diff --git a/src/zbl-zcl.c b/src/zbl-zcl.c index 3c0f845..5dc51cd 100644 --- a/src/zbl-zcl.c +++ b/src/zbl-zcl.c @@ -55,6 +55,9 @@ API int zb_read_attr_status_record_clone(zb_zcl_read_attr_status_record_h src, RETV_IF(NULL == src, ZIGBEE_ERROR_INVALID_PARAMETER); RETV_IF(NULL == dst, ZIGBEE_ERROR_INVALID_PARAMETER); + len = zb_zcl_get_data_size(srcs->type); + RETV_IF(0 >= len, ZIGBEE_ERROR_NO_DATA); + desc = calloc(1, sizeof(struct read_attribute_status_record_s)); RETVM_IF(NULL == desc, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); @@ -67,8 +70,6 @@ API int zb_read_attr_status_record_clone(zb_zcl_read_attr_status_record_h src, return ZIGBEE_ERROR_OUT_OF_MEMORY; } - len = zb_zcl_get_data_size(srcs->type); - RETV_IF(0 >= len, ZIGBEE_ERROR_NO_DATA); memcpy(desc->value, srcs->value, len); *dst = desc; @@ -379,12 +380,15 @@ API int zb_write_attr_record_clone(zb_zcl_write_attr_record_h src, RETV_IF(NULL == src, ZIGBEE_ERROR_INVALID_PARAMETER); RETV_IF(NULL == dst, ZIGBEE_ERROR_INVALID_PARAMETER); + len = zb_zcl_get_data_size(srcs->type); + RETV_IF(0 >= len, ZIGBEE_ERROR_NO_DATA); + desc = calloc(1, sizeof(struct write_attribute_record_s)); RETVM_IF(NULL == desc, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); memcpy(desc, src, sizeof(struct write_attribute_record_s)); - desc->value = calloc(1, zb_zcl_get_data_size(srcs->type)); + desc->value = calloc(1, len); if (NULL == desc->value) { free(desc); desc = NULL; @@ -393,9 +397,6 @@ API int zb_write_attr_record_clone(zb_zcl_write_attr_record_h src, return ZIGBEE_ERROR_OUT_OF_MEMORY; } - len = zb_zcl_get_data_size(srcs->type); - RETV_IF(0 >= len, ZIGBEE_ERROR_NO_DATA); - memcpy(desc->value, srcs->value, len); *dst = desc; @@ -612,12 +613,15 @@ API int zb_report_config_record_clone(zb_zcl_reporting_config_record_h src, RETV_IF(NULL == src, ZIGBEE_ERROR_INVALID_PARAMETER); RETV_IF(NULL == dst, ZIGBEE_ERROR_INVALID_PARAMETER); + len = zb_zcl_get_data_size(srcs->type); + RETV_IF(0 >= len, ZIGBEE_ERROR_NO_DATA); + desc = calloc(1, sizeof(struct reporting_configuration_record_s)); RETVM_IF(NULL == desc, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); memcpy(desc, src, sizeof(struct reporting_configuration_record_s)); - desc->change = calloc(1, zb_zcl_get_data_size(srcs->type)); + desc->change = calloc(1, len); if (NULL == desc->change) { free(desc); desc = NULL; @@ -625,9 +629,6 @@ API int zb_report_config_record_clone(zb_zcl_reporting_config_record_h src, return ZIGBEE_ERROR_OUT_OF_MEMORY; } - len = zb_zcl_get_data_size(srcs->type); - RETV_IF(0 >= len, ZIGBEE_ERROR_NO_DATA); - memcpy(desc->change, srcs->change, len); *dst = desc; -- 2.7.4