From d0869ae3ba4d1622ebd849ec85d9dde8682c2d68 Mon Sep 17 00:00:00 2001 From: Jeon Sang-Heon Date: Wed, 5 Aug 2020 11:18:16 +0000 Subject: [PATCH] Fix svace issue - Check file pointer is null - Initialize curl error enum code - WGID: 445288 Change-Id: I074f18b48c095dd7d75bc03ce33218ac080ae1c9 Signed-off-by: Jeon Sang-Heon --- src/plugin/http_util.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/plugin/http_util.c b/src/plugin/http_util.c index 1849485..7b826dc 100644 --- a/src/plugin/http_util.c +++ b/src/plugin/http_util.c @@ -310,8 +310,9 @@ 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; + CURLcode err = CURLE_OK; + int ret_code = 0; + int curl_ret_code = CURLE_OK; curl = curl_easy_init(); retvm_if(!curl, -EIO, "Failed to init curl"); @@ -332,6 +333,10 @@ int http_util_download_file(const char *download_url, const char *download_path, #endif fp = fopen(download_path, "wb"); + if (fp == NULL) { + _E("Failed to open %s", download_path); + goto clean; + } curl_ret_code = curl_easy_setopt(curl, CURLOPT_URL, download_url); if (CURLE_OK != curl_ret_code) { @@ -355,11 +360,14 @@ int http_util_download_file(const char *download_url, const char *download_path, clean: curl_easy_cleanup(curl); - fclose(fp); - if (CURLE_OK != curl_ret_code) { - return -EIO; - } + if (fp != NULL) + fclose(fp); + else + ret_code = -EIO; + + if (CURLE_OK != curl_ret_code) + ret_code = -EIO; #ifdef DOWNLOAD_MONITORING int status; @@ -370,10 +378,10 @@ clean: _I("Failed to download file[%s, %d]", curl_easy_strerror(err), err); if (remove(download_path) < 0) _E("Failed to remove [%s]", download_path); - return -EIO; + ret_code = -EIO; } - return 0; + return ret_code; } int http_util_send_request(fmwup_http_e type, const char *req_url, char **res_header, char **res_body) -- 2.34.1