From a6423fa3fb903ea505074117cd7db66507a76f9c Mon Sep 17 00:00:00 2001 From: Daesung Date: Fri, 29 Sep 2017 01:52:07 +0900 Subject: [PATCH] Fix svace errors st_things_request_handler.c - In error statement, make the func to return false cloud_connector.c - 'registerPayload' & 'loginoutPayload' are released in 'OCDoResource' - So, add 'OCRepPayloadDestroy' to release in error state. easysetup_manager.c - Add check statement before close file descriptor resource_handler.c - change 'strncmp' which is using just for empty checking to 'strlen' things_req_handler.c - initialize variable before using things_security_manager.c - Add fclose after usage of fds. things_string_utils.c - Add '+1' when check string length for null character. --- .../src/st_things/st_things_request_handler.c | 1 + .../src/common/cloud/cloud_connector.c | 4 ++++ .../src/common/easy-setup/easysetup_manager.c | 24 ++++++++++++++-------- .../src/common/easy-setup/resource_handler.c | 2 +- .../src/common/framework/things_req_handler.c | 3 ++- .../src/common/framework/things_security_manager.c | 2 ++ .../src/common/utils/things_string_util.c | 2 +- 7 files changed, 27 insertions(+), 11 deletions(-) diff --git a/framework/src/st_things/st_things_request_handler.c b/framework/src/st_things/st_things_request_handler.c index f38125b..c452e2a 100644 --- a/framework/src/st_things/st_things_request_handler.c +++ b/framework/src/st_things/st_things_request_handler.c @@ -90,6 +90,7 @@ bool get_query_value_internal(const char *query, const char *key, char **value, if (NULL == *value) { ST_LOG(ST_ERROR, "Failed to clone the query value."); util_free(p_origin); + return false; } else { res = true; } diff --git a/framework/src/st_things/things_stack/src/common/cloud/cloud_connector.c b/framework/src/st_things/things_stack/src/common/cloud/cloud_connector.c index d03c412..7a5d5e8 100644 --- a/framework/src/st_things/things_stack/src/common/cloud/cloud_connector.c +++ b/framework/src/st_things/things_stack/src/common/cloud/cloud_connector.c @@ -196,6 +196,8 @@ OCStackResult things_cloud_signup(const char *host, const char *device_id, const create_time_out_process(g_req_handle, timeoutHandler, timeout); } + } else { + OCRepPayloadDestroy(registerPayload); } return result; @@ -280,6 +282,8 @@ OCStackResult things_cloud_session(const char *host, const char *uId, const char create_time_out_process(g_req_handle, timeoutHandler, timeout); } + } else { + OCRepPayloadDestroy(loginoutPayload); } if (IoTivityVer) { diff --git a/framework/src/st_things/things_stack/src/common/easy-setup/easysetup_manager.c b/framework/src/st_things/things_stack/src/common/easy-setup/easysetup_manager.c index e535e4e..58379e2 100644 --- a/framework/src/st_things/things_stack/src/common/easy-setup/easysetup_manager.c +++ b/framework/src/st_things/things_stack/src/common/easy-setup/easysetup_manager.c @@ -247,10 +247,14 @@ esm_result_e esm_init_easysetup(int restart_flag, things_server_builder_s *serve } } pthread_join(gthread_id_cloud_refresh_check, NULL); - close(ci_token_expire_fds[0]); - close(ci_token_expire_fds[1]); - ci_token_expire_fds[0] = -1; - ci_token_expire_fds[1] = -1; + if (ci_token_expire_fds[0] != -1) { + close(ci_token_expire_fds[0]); + ci_token_expire_fds[0] = -1; + } + if (ci_token_expire_fds[1] != -1) { + close(ci_token_expire_fds[1]); + ci_token_expire_fds[1] = -1; + } #else pthread_join(gthread_id_cloud_refresh_check, NULL); #endif @@ -337,10 +341,14 @@ esm_result_e esm_init_easysetup(int restart_flag, things_server_builder_s *serve if (gthread_id_cloud_refresh_check == 0) { int ret = pipe(ci_token_expire_fds); if (-1 == ret) { - close(ci_token_expire_fds[0]); - close(ci_token_expire_fds[1]); - ci_token_expire_fds[0] = -1; - ci_token_expire_fds[1] = -1; + if (ci_token_expire_fds[0] != -1) { + close(ci_token_expire_fds[0]); + ci_token_expire_fds[0] = -1; + } + if (ci_token_expire_fds[1] != -1) { + close(ci_token_expire_fds[1]); + ci_token_expire_fds[1] = -1; + } THINGS_LOG_D_ERROR(THINGS_ERROR, TAG, "pipe failed: %s", strerror(errno)); return ESM_ERROR; } diff --git a/framework/src/st_things/things_stack/src/common/easy-setup/resource_handler.c b/framework/src/st_things/things_stack/src/common/easy-setup/resource_handler.c index 239bbfd..6e2da78 100644 --- a/framework/src/st_things/things_stack/src/common/easy-setup/resource_handler.c +++ b/framework/src/st_things/things_stack/src/common/easy-setup/resource_handler.c @@ -1032,7 +1032,7 @@ OCRepPayload *construct_response_of_prov(OCEntityHandlerRequest *eh_request) return NULL; } // Requested interface is Link list interface - if (!eh_request->query || (eh_request->query && !strncmp(eh_request->query, "", strlen(eh_request->query))) || (eh_request->query && compare_resource_interface(eh_request->query, OC_RSRVD_INTERFACE_LL)) || (eh_request->query && compare_resource_interface(eh_request->query, OC_RSRVD_INTERFACE_DEFAULT))) { + if (!eh_request->query || (eh_request->query && (strlen(eh_request->query) > 0)) || (eh_request->query && compare_resource_interface(eh_request->query, OC_RSRVD_INTERFACE_LL)) || (eh_request->query && compare_resource_interface(eh_request->query, OC_RSRVD_INTERFACE_DEFAULT))) { if ((arrayPayload[childResCnt] = make_rep_payload(g_wifi_resource.handle, &eh_request->devAddr)) == NULL) { THINGS_LOG_ERROR(THINGS_ERROR, ES_RH_TAG, "It's failed making payload of wifi_resource_s-Representation"); goto GOTO_FAILED; diff --git a/framework/src/st_things/things_stack/src/common/framework/things_req_handler.c b/framework/src/st_things/things_stack/src/common/framework/things_req_handler.c index 80a5bce..c64e6ba 100644 --- a/framework/src/st_things/things_stack/src/common/framework/things_req_handler.c +++ b/framework/src/st_things/things_stack/src/common/framework/things_req_handler.c @@ -80,6 +80,7 @@ OCEntityHandlerResult things_abort(pthread_t *h_thread_abort, things_es_enrollee static int verify_request(OCEntityHandlerRequest *eh_request, const char *uri, int req_type) { int result = 0; + things_resource_s *pst_temp_resource = NULL; if (g_builder == NULL) { THINGS_LOG_ERROR(THINGS_ERROR, TAG, "Server Builder is not registered.."); @@ -93,7 +94,7 @@ static int verify_request(OCEntityHandlerRequest *eh_request, const char *uri, i things_resource_s *child = NULL; /*! Added by st_things for memory Leak fix */ - things_resource_s *pst_temp_resource = resource; + pst_temp_resource = resource; if (resource == NULL) { THINGS_LOG_V_ERROR(THINGS_ERROR, TAG, "Resource Not found : %s ", uri); goto EXIT_VALIDATION; diff --git a/framework/src/st_things/things_stack/src/common/framework/things_security_manager.c b/framework/src/st_things/things_stack/src/common/framework/things_security_manager.c index fd43e31..d2dba59 100644 --- a/framework/src/st_things/things_stack/src/common/framework/things_security_manager.c +++ b/framework/src/st_things/things_stack/src/common/framework/things_security_manager.c @@ -233,11 +233,13 @@ static OCStackResult seckey_setup(const char *filename, OicSecKey_t *key, OicEnc if (key->data == NULL) { THINGS_LOG_D(THINGS_ERROR, TAG, "Memory Full"); THINGS_LOG_D(THINGS_DEBUG, TAG, "OUT[FAIL]: %s", __func__); + fclose(fp); return OC_STACK_NO_MEMORY; } fread(key->data, 1, size, fp); key->len = size; key->encoding = encoding; + fclose(fp); } THINGS_LOG_D(THINGS_DEBUG, TAG, "OUT: %s", __func__); diff --git a/framework/src/st_things/things_stack/src/common/utils/things_string_util.c b/framework/src/st_things/things_stack/src/common/utils/things_string_util.c index 32918dd..9126623 100644 --- a/framework/src/st_things/things_stack/src/common/utils/things_string_util.c +++ b/framework/src/st_things/things_stack/src/common/utils/things_string_util.c @@ -74,7 +74,7 @@ void concat_string(char **target, char *attach) *target = NULL; } - if (MAX_BUF_LEN >= (strlen(buf) + strlen(attach))) { + if (MAX_BUF_LEN >= (strlen(buf) + strlen(attach) + 1)) { strncat(buf, attach, MAX_BUF_LEN); } else { THINGS_LOG_ERROR(THINGS_ERROR, TAG, "Something went wrong"); -- 2.7.4