Fix unexpected crash on lib side.
authorJiwan Kim <ji-wan.kim@samsung.com>
Fri, 24 Mar 2017 04:29:16 +0000 (13:29 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 11 May 2017 09:07:20 +0000 (18:07 +0900)
- 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 <ji-wan.kim@samsung.com>
common/zb_common.h
lib/zbl_dbus.c
lib/zbl_dbus.h
lib/zbl_zcl.c
lib/zbl_zdo_dev_disc.c
test/main.c
test/zcl_global_cmd.c

index ce8431627b59bdb32aacd090cfdd69751ce752d7..a37793171baa3a90116904e64baa744d22b0fd9d 100644 (file)
 
 #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(); \
index a2694ec44e6e79e480bad3e72498fc2d7c9434fa..5fbafb00d9fe5e36be6010d828c77f3dcb19c9ec 100644 (file)
@@ -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);
index 1668d9ca3575b351947c8c19989d9743507063bb..2d2c74cbb9460083fb3198dcfd3a7c0eb3b795be 100644 (file)
@@ -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,
index abdb8c6ad1e3f16ccd3f0355ecfd66e488bf6c95..c5532e8a3b54993a92b57ae5d1f1199c90755bdf 100644 (file)
@@ -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;
index 313bef1be5880d4b368f6f5b2c5f8caa1b2979ed..f0bf4df4c17301759a2e3700db4136125603cea6 100644 (file)
@@ -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,
index fa9cc31ee3eda237f911164880adb1c9816e15db..f2c573b532f2fc5c850080b183d6811d6f30c28a 100644 (file)
@@ -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;
        }
index 271a96e55bf7da98d28120b1380e23353356e113..f937947bc0c5f2576cddfcb05b47607ac28bab27 100644 (file)
@@ -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);