From 167e8b7af4b9616e30ac0eab8e7e7ac95adf1258 Mon Sep 17 00:00:00 2001 From: Jeon Sang-Heon Date: Fri, 31 Jan 2020 11:30:46 +0900 Subject: [PATCH] Fix: fix coverity issue - modify uncatched return code from curl_easy_setopt - modify misused G_FREE to G_FREE Change-Id: Ia4bfd345a545d9c2043d60e6ca50f3dcf1e88a1c --- src/plugin/http_util.c | 31 +++++++++++++++++++++++-------- src/plugin/plugin.c | 6 +++--- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/plugin/http_util.c b/src/plugin/http_util.c index 498fa1e..c428512 100644 --- a/src/plugin/http_util.c +++ b/src/plugin/http_util.c @@ -91,7 +91,10 @@ static void __curl_set_request_headers(CURL *curl) header = curl_slist_append(header, tmp_header); g_free(tmp_header); - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header); + int curl_ret_code = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header); + if (CURLE_OK != curl_ret_code) { + _E("curl_easy_setopt: CURLOPT_HTTPHEADER failed!! curl_ret_code[%d]", curl_ret_code); + } } static size_t __gather_data(void *downloaded_data, @@ -246,11 +249,13 @@ int http_util_check_request_to_fota(const char *uid, char *tmp_header = NULL; char *req_url = NULL; char query[128]; + int curl_ret_code = 0; curl = curl_easy_init(); retvm_if(!curl, -EIO, "Failed to init curl"); - curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); + curl_ret_code = curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); + retvm_if(CURLE_OK != curl_ret_code, -EIO, "Failed to curl_easy_setopt with CURLOPT_HTTPGET : ret_code[%d]", curl_ret_code); tmp_header = g_strconcat("X-IOT-UID: ", uid, NULL); header = curl_slist_append(header, tmp_header); @@ -259,7 +264,8 @@ int http_util_check_request_to_fota(const char *uid, header = curl_slist_append(header, tmp_header); g_free(tmp_header); - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header); + curl_ret_code = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header); + retvm_if(CURLE_OK != curl_ret_code, -EIO, "Failed to curl_easy_setopt with CURLOPT_HTTPHEADER : ret_code[%d]", curl_ret_code); snprintf(query, sizeof(query), "?deviceType=%s¤tVersion=%s", device_type, current_version); req_url = g_strconcat(STDM_URL, query, NULL); @@ -305,6 +311,7 @@ int http_util_download_file(const char *download_url, const char *download_path, FILE *fp = NULL; CURL *curl = NULL; CURLcode err; + int curl_ret_code = 0; curl = curl_easy_init(); retvm_if(!curl, -EIO, "Failed to init curl"); @@ -326,9 +333,14 @@ int http_util_download_file(const char *download_url, const char *download_path, fp = fopen(download_path, "wb"); - curl_easy_setopt(curl, CURLOPT_URL, download_url); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); + curl_ret_code = curl_easy_setopt(curl, CURLOPT_URL, download_url); + retvm_if(CURLE_OK != curl_ret_code, -EIO, "Failed to curl_easy_setopt with CURLOPT_URL : ret_code[%d]", curl_ret_code); + + curl_ret_code = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL); + retvm_if(CURLE_OK != curl_ret_code, -EIO, "Failed to curl_easy_setopt with CURLOPT_WRITEFUNCTION : ret_code[%d]", curl_ret_code); + + curl_ret_code = curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); + retvm_if(CURLE_OK != curl_ret_code, -EIO, "Failed to curl_easy_setopt with CURLOPT_WRITEDATA : ret_code[%d]", curl_ret_code); err = curl_easy_perform(curl); @@ -357,6 +369,7 @@ int http_util_send_request(fmwup_http_e type, const char *req_url, char **res_he GByteArray *response_header = NULL; GByteArray *response_body= NULL; CURLcode err; + int curl_ret_code = 0; curl = curl_easy_init(); retvm_if(!curl, -EIO, "Failed to init curl"); @@ -364,9 +377,11 @@ int http_util_send_request(fmwup_http_e type, const char *req_url, char **res_he __curl_set_request_headers(curl); if (type == FMWUP_HTTP_GET) { - curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); + curl_ret_code = curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); + retvm_if(CURLE_OK != curl_ret_code, -EIO, "Failed to curl_easy_setopt with CURLOPT_HTTPGET : ret_code[%d]", curl_ret_code); } else if (type == FMWUP_HTTP_POST) { - curl_easy_setopt(curl, CURLOPT_HTTPPOST, 1); + curl_ret_code = curl_easy_setopt(curl, CURLOPT_HTTPPOST, 1); + retvm_if(CURLE_OK != curl_ret_code, -EIO, "Failed to curl_easy_setopt with CURLOPT_HTTPPOST : ret_code[%d]", curl_ret_code); } else { return -1; } diff --git a/src/plugin/plugin.c b/src/plugin/plugin.c index c37d41d..13e6efd 100644 --- a/src/plugin/plugin.c +++ b/src/plugin/plugin.c @@ -666,7 +666,7 @@ API int update_control_download_package(void) package_downloaded = true; exit: - G_FREE(app_path); + free(app_path); G_FREE(download_url); G_FREE(download_path); @@ -702,7 +702,7 @@ API int update_control_do_update(void) path = g_strconcat(app_path, FIRMWARE_FILE_NAME, NULL); if (!path) { _E("Failed to g_strconcat"); - G_FREE(app_path); + free(app_path); return UPDATE_CONTROL_ERROR_SYSTEM_ERROR; } @@ -715,7 +715,7 @@ API int update_control_do_update(void) /* Should be unreachable */ _E("Update reboot timed out"); - G_FREE(app_path); + free(app_path); G_FREE(path); return UPDATE_CONTROL_ERROR_TIMED_OUT; -- 2.34.1