From: Jiwan Kim Date: Fri, 24 Mar 2017 04:29:16 +0000 (+0900) Subject: Fix unexpected crash on lib side. X-Git-Tag: submit/tizen/20170512.045637~21 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9af8a4a92cc78a4b6e448c0e174c4e2d3ff5968a;p=platform%2Fcore%2Fapi%2Fzigbee.git Fix unexpected crash on lib side. - Fix null check sequence in order to prevent unexpected crash on complicated allocation. - Add missing API call (zb_zdo_user_desc_set) - Displays error code on feature check logic - Check memory allocation failure on test code. Change-Id: Ifc8fe7ae22374efe26bc192c4c5d3a11ca7e4ece Signed-off-by: Jiwan Kim --- diff --git a/common/zb_common.h b/common/zb_common.h index ce84316..a377931 100644 --- a/common/zb_common.h +++ b/common/zb_common.h @@ -25,24 +25,19 @@ #define ZIGBEE_FEATURE "http://tizen.org/feature/network.zigbee" -#if 0 #define CHECK_FEATURE_SUPPORTED(feature_name) { \ bool zigbee_supported = FALSE; \ - if (!system_info_get_platform_bool(feature_name, &zigbee_supported)) { \ + int si_ret = system_info_get_platform_bool(feature_name, &zigbee_supported); \ + if (si_ret == SYSTEM_INFO_ERROR_NONE) { \ if (zigbee_supported == FALSE) { \ ERR("zigbee feature is disabled"); \ return ZIGBEE_ERROR_NOT_SUPPORTED; \ } \ } else { \ - ERR("Error - Feature getting from System Info"); \ + ERR("Error - Feature getting from System Info [0x%X]", si_ret); \ return ZIGBEE_ERROR_OPERATION_FAILED; \ } \ } -#else -#define CHECK_FEATURE_SUPPORTED(feature_name) { \ - ERR("Should be check !"); \ - } -#endif #define CHECK_ZIGBEE_PRIVILEGE() { \ int zb_check_priv = zbl_check_privilege(); \ diff --git a/lib/zbl_dbus.c b/lib/zbl_dbus.c index a2694ec..5fbafb0 100644 --- a/lib/zbl_dbus.c +++ b/lib/zbl_dbus.c @@ -4339,7 +4339,6 @@ int zbl_user_desc_set(zigbee_h handle, nwk_addr addr16, unsigned char len, RETV_IF(NULL == zdo_dev_proxy, ZIGBEE_ERROR_IO_ERROR); RETVM_IF(len > MAX_USER_DESC_SIZE || len < 0x00, ZIGBEE_ERROR_INVALID_PARAMETER, "invalid length=%d", len); - RETVM_IF(NULL == user_data, ZIGBEE_ERROR_INVALID_PARAMETER, "invalid data"); container = calloc(1, sizeof(zbl_req_cb_s)); RETVM_IF(NULL == container, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); diff --git a/lib/zbl_dbus.h b/lib/zbl_dbus.h index 1668d9c..2d2c74c 100644 --- a/lib/zbl_dbus.h +++ b/lib/zbl_dbus.h @@ -60,10 +60,13 @@ int zbl_match_desc_req(zigbee_h handle, nwk_addr addr16, unsigned short *out_clusters, zb_zdo_match_desc_rsp cb, void *user_data); int zbl_device_annce(zigbee_h handle, nwk_addr addr16, ieee_addr addr64, unsigned char capability); + int zbl_node_desc_req(nwk_addr addr16, zb_zdo_node_desc_rsp cb, void *user_data); int zbl_power_desc_req(nwk_addr addr16, zb_zdo_power_desc_rsp cb, void *user_data); int zbl_complex_desc_req(nwk_addr addr16, zb_zdo_complex_desc_rsp cb, void *user_data); int zbl_user_desc_req(nwk_addr addr16, zb_zdo_user_desc_rsp cb, void *user_data); +int zbl_user_desc_set(zigbee_h handle, nwk_addr addr16, unsigned char len, + unsigned char *user_desc, zb_zdo_user_desc_conf cb, void *user_data); int zbl_bind_req(nwk_addr dst_addr16, ieee_addr src_addr64, unsigned char src_ep, unsigned short cluster_id, ieee_addr dst_addr64, unsigned char type, nwk_addr group_addr, unsigned char dst_ep, zb_zdo_bind_rsp cb, diff --git a/lib/zbl_zcl.c b/lib/zbl_zcl.c index abdb8c6..c5532e8 100644 --- a/lib/zbl_zcl.c +++ b/lib/zbl_zcl.c @@ -432,13 +432,12 @@ API int zb_create_read_attr_status_record(read_attr_status_record_h *handle) read_attr_status_record_h simple = NULL; CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE); - RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER); - RETVM_IF(NULL == simple, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); - CHECK_ZIGBEE_PRIVILEGE(); simple = calloc(1, sizeof(struct read_attribute_status_record_s)); + RETVM_IF(NULL == simple, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); + *handle = simple; return ZIGBEE_ERROR_NONE; @@ -838,13 +837,12 @@ API int zb_create_write_attr_record( write_attr_record_h t = NULL; CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE); - RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER); - RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); - CHECK_ZIGBEE_PRIVILEGE(); t = calloc(1, sizeof(struct write_attribute_record_s)); + RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); + *handle = t; return ZIGBEE_ERROR_NONE; } @@ -968,13 +966,11 @@ API int zb_create_write_attr_status(write_attr_status_record_h *handle) write_attr_status_record_h simple = NULL; CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE); - RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER); - RETVM_IF(NULL == simple, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); - CHECK_ZIGBEE_PRIVILEGE(); simple = calloc(1, sizeof(struct write_attribute_status_record_s)); + RETVM_IF(NULL == simple, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); *handle = simple; return ZIGBEE_ERROR_NONE; @@ -1356,13 +1352,11 @@ API int zb_create_read_report_config_record(read_report_config_record_h *handle) read_report_config_record_h t = NULL; CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE); - RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER); - RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); - CHECK_ZIGBEE_PRIVILEGE(); t = calloc(1, sizeof(struct read_reporting_configuration_record_s)); + RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); *handle = t; return ZIGBEE_ERROR_NONE; @@ -1429,13 +1423,11 @@ API int zb_create_report_config_response_record( report_config_response_record_h t = NULL; CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE); - RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER); - RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); - CHECK_ZIGBEE_PRIVILEGE(); t = calloc(1, sizeof(struct reporting_configuration_response_record_s)); + RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); *handle = t; return ZIGBEE_ERROR_NONE; @@ -1529,13 +1521,11 @@ API int zb_create_attr_report(attr_report_h *handle) attr_report_h t = NULL; CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE); - RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER); - RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); - CHECK_ZIGBEE_PRIVILEGE(); t = calloc(1, sizeof(struct attribute_report_s)); + RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); *handle = t; return ZIGBEE_ERROR_NONE; @@ -1761,13 +1751,11 @@ API int zb_create_extended_attr_info(extended_attr_info_h *handle) extended_attr_info_h t = NULL; CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE); - RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER); - RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); - CHECK_ZIGBEE_PRIVILEGE(); t = calloc(1, sizeof(struct extended_attribute_infomation_s)); + RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno); *handle = t; return ZIGBEE_ERROR_NONE; diff --git a/lib/zbl_zdo_dev_disc.c b/lib/zbl_zdo_dev_disc.c index 313bef1..f0bf4df 100644 --- a/lib/zbl_zdo_dev_disc.c +++ b/lib/zbl_zdo_dev_disc.c @@ -162,12 +162,14 @@ API int zb_zdo_user_desc_req(zigbee_h handle, nwk_addr addr16, API int zb_zdo_user_desc_set(zigbee_h handle, nwk_addr addr16, unsigned char len, unsigned char *user_desc, zb_zdo_user_desc_conf cb, void *user_data) { + int ret; CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE); RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER); RETV_IF(NULL == zbl_dbus_get_object(), ZIGBEE_ERROR_IO_ERROR); RETV_IF(0 == addr16, ZIGBEE_ERROR_INVALID_ADDRESS); RETV_IF(NULL == user_desc, ZIGBEE_ERROR_INVALID_PARAMETER); - return ZIGBEE_ERROR_NONE; + ret = zbl_user_desc_set(handle, addr16, len, user_desc, cb, user_data); + return ret; } API int zb_zdo_device_annce(zigbee_h handle, nwk_addr addr16, ieee_addr addr64, diff --git a/test/main.c b/test/main.c index fa9cc31..f2c573b 100644 --- a/test/main.c +++ b/test/main.c @@ -526,7 +526,7 @@ static int run_enable(MManager *mm, struct menu_data *menu) /* Enable */ ret = zb_enable(handle, zigbee_enable_cb, NULL); if (ZIGBEE_ERROR_NONE != ret) { - msg("zb_enable(0x%X) - FAILED!!!", ret); + msg("zb_enable(0x%X) - FAILED!!! [%s]", ret, zigbee_error_to_string(ret)); return RET_FAILURE; } @@ -696,11 +696,11 @@ static int run_get_endpoint_list(MManager *mm, struct menu_data *menu) ret = zb_get_endpoint_list(handle, dest_addr64, &count, ep_list); if (ZIGBEE_ERROR_NONE != ret) { - msg("zb_get_endpoint_list(%d) - FAILED!!!", ret); + msg("zb_get_endpoint_list(%d) - FAILED!!! [%s]", ret, zigbee_error_to_string(ret)); return RET_FAILURE; } - msg(" - zb_get_endpoint_list() ret: [0x%X] [%s]", ret, zigbee_error_to_string(ret)); + msg(" - zb_get_endpoint_list() ret: [0x%X]", ret); msgb("Endpoints count [%d] : ", count); for(i = 0; i < count; i++) { msgn(" %04d", ep_list[i]); @@ -728,11 +728,11 @@ static int run_get_cluster_list(MManager *mm, struct menu_data *menu) &in_count, in_cluster_list, &out_count, out_cluster_list); if (ZIGBEE_ERROR_NONE != ret) { - msg("zb_get_cluster_list(%d) - FAILED!!!", ret); + msg("zb_get_cluster_list(%d) - FAILED!!! [%s]", ret, zigbee_error_to_string(ret)); return RET_FAILURE; } - msg(" - zb_get_cluster_list() ret: [0x%X] [%s]", ret, zigbee_error_to_string(ret)); + msg(" - zb_get_cluster_list() ret: [0x%X]", ret); msgb("In Clusters count [%d] : ", in_count); for(i = 0; i < in_count; i++) { msgn(" %04X (%s)\n", in_cluster_list[i], zb_get_cluster_name(in_cluster_list[i])); @@ -1016,7 +1016,11 @@ static int __select_handle_register_event(MManager *mm, struct menu_data *menu) /* Enable */ ret = zb_enable(handle, zigbee_enable_cb, NULL); - if (ZIGBEE_ERROR_NONE != ret) { + if (ZIGBEE_ERROR_PERMISSION_DENIED == ret) { + /* Admin permission is not set, but we can do normal operations */ + msg("zb_enable(0x%X) - FAILED!!!", ret); + } + else if (ZIGBEE_ERROR_NONE != ret) { msg("zb_enable(0x%X) - FAILED!!! [%s]", ret, zigbee_error_to_string(ret)); return RET_FAILURE; } diff --git a/test/zcl_global_cmd.c b/test/zcl_global_cmd.c index 271a96e..f937947 100644 --- a/test/zcl_global_cmd.c +++ b/test/zcl_global_cmd.c @@ -67,6 +67,7 @@ static void zigbee_zcl_global_read_attributes_rsp(nwk_addr addr16, int records_len, void *user_data) { int count; + int ret; unsigned short id; unsigned char type; unsigned char status; @@ -89,7 +90,13 @@ static void zigbee_zcl_global_read_attributes_rsp(nwk_addr addr16, } records = records_info->record.read_attr; - zb_create_value(&value); + ret = zb_create_value(&value); + if (ZIGBEE_ERROR_NONE != ret) { + msg("zb_create_value(0x%X) - FAILED!!! [%s]", + ret, zigbee_error_to_string(ret)); + return RET_FAILURE; + } + msg(" Cluster ID : 0x%04X (%s)", cluster_id, zb_get_cluster_name(cluster_id)); msg(" Node ID : 0x%04X", addr16); msg(" End-Point : 0x%02X", ep); @@ -124,6 +131,7 @@ static void zigbee_zcl_global_write_attributes_rsp(nwk_addr addr16, unsigned char ep, unsigned short cluster_id, zb_global_record_data_s *records_info, int records_len, void *user_data) { + int ret; unsigned short id = 0; unsigned char status; zb_value_h value = NULL; @@ -139,7 +147,13 @@ static void zigbee_zcl_global_write_attributes_rsp(nwk_addr addr16, } records = records_info->record.write_attr; - zb_create_value(&value); + ret = zb_create_value(&value); + if (ZIGBEE_ERROR_NONE != ret) { + msg("zb_create_value(0x%X) - FAILED!!! [%s]", + ret, zigbee_error_to_string(ret)); + return RET_FAILURE; + } + msg(" Cluster ID : 0x%04X (%s)", cluster_id, zb_get_cluster_name(cluster_id)); msg(" Node ID : 0x%04X", addr16); msg(" End-Point : 0x%02X", ep); @@ -220,7 +234,13 @@ static void zigbee_zcl_global_read_reporting_configuration_rsp(nwk_addr addr16, msg(" Max Interval 0x%04X", max_i); zb_get_min_i_from_report_config_record(records[i], &min_i); msg(" Min Interval 0x%04X", min_i); - zb_create_value(&val); + ret = zb_create_value(&val); + if (ZIGBEE_ERROR_NONE != ret) { + msg("zb_create_read_report_config_record(0x%X) - FAILED!!! [%s]", + ret, zigbee_error_to_string(ret)); + continue; + } + zb_get_change_from_report_config_record1(records[i], val); ret = zb_get_value(val, &type, &buf, &count); if (ZIGBEE_ERROR_NONE == ret) { @@ -408,7 +428,13 @@ static int run_global_write_attr(MManager *mm, struct menu_data *menu) memcpy(attribute_value, &temp, sizeof(unsigned short)); } - zb_create_write_attr_record(&attr); + ret = zb_create_write_attr_record(&attr); + if (ZIGBEE_ERROR_NONE != ret) { + msg("zb_create_write_attr_record(0x%X) - FAILED!!! [%s]", + ret, zigbee_error_to_string(ret)); + return RET_FAILURE; + } + //zb_set_id_to_write_attr_record(attr, ZB_ZCL_IDENTIFY_TIME_ATTRIBUTE_ID); zb_set_id_to_write_attr_record(attr, attribute_id); zb_set_type_to_write_attr_record(attr, ZB_ZCL_UNSIGNED_16_BIT_INTEGER); @@ -438,7 +464,13 @@ static int run_global_write_attr_undivided(MManager *mm, struct menu_data *menu) /* Samjin Power Outlet */ write_attr_record_h attr; - zb_create_write_attr_record(&attr); + ret = zb_create_write_attr_record(&attr); + if (ZIGBEE_ERROR_NONE != ret) { + msg("zb_create_write_attr_record(0x%X) - FAILED!!! [%s]", + ret, zigbee_error_to_string(ret)); + return RET_FAILURE; + } + zb_set_id_to_write_attr_record(attr, ZB_ZCL_IDENTIFY_TIME_ATTRIBUTE_ID); zb_set_type_to_write_attr_record(attr, ZB_ZCL_UNSIGNED_16_BIT_INTEGER); zb_set_buf_to_write_attr_record(attr, ZB_ZCL_UNSIGNED_16_BIT_INTEGER, value, @@ -465,7 +497,13 @@ static int run_global_write_attr_no_rsp(MManager *mm, struct menu_data *menu) /* Samjin Power Outlet */ write_attr_record_h attr; - zb_create_write_attr_record(&attr); + ret = zb_create_write_attr_record(&attr); + if (ZIGBEE_ERROR_NONE != ret) { + msg("zb_create_write_attr_record(0x%X) - FAILED!!! [%s]", + ret, zigbee_error_to_string(ret)); + return RET_FAILURE; + } + zb_set_id_to_write_attr_record(attr, ZB_ZCL_IDENTIFY_TIME_ATTRIBUTE_ID); zb_set_type_to_write_attr_record(attr, ZB_ZCL_UNSIGNED_16_BIT_INTEGER); zb_set_buf_to_write_attr_record(attr, ZB_ZCL_UNSIGNED_16_BIT_INTEGER, value, @@ -508,7 +546,13 @@ static int run_global_config_report(MManager *mm, struct menu_data *menu) if (strlen(data_timeout)) timeout = (unsigned short)strtol(data_timeout, NULL, 10); - zb_create_report_config_record(&config); + ret = zb_create_report_config_record(&config); + if (ZIGBEE_ERROR_NONE != ret) { + msg("zb_create_report_config_record(0x%X) - FAILED!!! [%s]", + ret, zigbee_error_to_string(ret)); + return RET_FAILURE; + } + zb_set_dir_to_report_config_record(config, ZB_ZCL_CLIENT_TO_SERVER); zb_set_id_to_report_config_record(config, attribute_id); zb_set_type_to_report_config_record(config, ZB_ZCL_BOOLEAN); @@ -526,7 +570,13 @@ static int run_global_config_report(MManager *mm, struct menu_data *menu) report_config_record_h config1; unsigned short val2 = 0x007f; - zb_create_report_config_record(&config1); + ret = zb_create_report_config_record(&config1); + if (ZIGBEE_ERROR_NONE != ret) { + msg("zb_create_report_config_record(0x%X) - FAILED!!! [%s]", + ret, zigbee_error_to_string(ret)); + return RET_FAILURE; + } + zb_set_dir_to_report_config_record(config1, ZB_ZCL_CLIENT_TO_SERVER); zb_set_id_to_report_config_record(config1, ZB_ZCL_ZONE_STATE_ATTRIBUTE_ID); zb_set_type_to_report_config_record(config1, ZB_ZCL_SIGNED_16_BIT_INTEGER); @@ -556,7 +606,13 @@ static int run_global_read_config_report(MManager *mm, struct menu_data *menu) int ret = ZIGBEE_ERROR_NONE; read_report_config_record_h read_report_conf; - zb_create_read_report_config_record(&read_report_conf); + ret = zb_create_read_report_config_record(&read_report_conf); + if (ZIGBEE_ERROR_NONE != ret) { + msg("zb_create_read_report_config_record(0x%X) - FAILED!!! [%s]", + ret, zigbee_error_to_string(ret)); + return RET_FAILURE; + } + zb_set_dir_to_read_report_config_record(read_report_conf, ZB_ZCL_CLIENT_TO_SERVER); zb_set_id_to_read_report_config_record(read_report_conf, ZB_ZCL_ON_OFF_ATTRIBUTE_ID);