|
|
c342a4 |
From 0311ac9d8368acd5baac8b7fc6f753bd895ea3fc Mon Sep 17 00:00:00 2001
|
|
|
c342a4 |
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
|
|
|
c342a4 |
Date: Tue, 6 Oct 2020 13:32:19 +0200
|
|
|
c342a4 |
Subject: [PATCH 1/2] Fix Coverity warnings
|
|
|
c342a4 |
|
|
|
c342a4 |
Addressing multiple Coverity defects similar to this one:
|
|
|
c342a4 |
Defect type: CHECKED_RETURN
|
|
|
c342a4 |
check_return: Calling "curl_easy_setopt(curl, _curl_opt, _curl_trace)"
|
|
|
c342a4 |
without checking return value. This library function may fail and return
|
|
|
c342a4 |
an error code.
|
|
|
c342a4 |
---
|
|
|
c342a4 |
src/common/oscap_acquire.c | 65 +++++++++++++++++++++++++++++++-------
|
|
|
c342a4 |
1 file changed, 53 insertions(+), 12 deletions(-)
|
|
|
c342a4 |
|
|
|
c342a4 |
diff --git a/src/common/oscap_acquire.c b/src/common/oscap_acquire.c
|
|
|
c342a4 |
index 666f4f5c9..34a92fa19 100644
|
|
|
c342a4 |
--- a/src/common/oscap_acquire.c
|
|
|
c342a4 |
+++ b/src/common/oscap_acquire.c
|
|
|
c342a4 |
@@ -326,18 +326,59 @@ char* oscap_acquire_url_download(const char *url, size_t* memory_size)
|
|
|
c342a4 |
return NULL;
|
|
|
c342a4 |
}
|
|
|
c342a4 |
|
|
|
c342a4 |
- struct oscap_buffer* buffer = oscap_buffer_new();
|
|
|
c342a4 |
-
|
|
|
c342a4 |
- curl_easy_setopt(curl, CURLOPT_URL, url);
|
|
|
c342a4 |
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_memory_callback);
|
|
|
c342a4 |
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer);
|
|
|
c342a4 |
- curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
|
|
|
c342a4 |
- curl_easy_setopt(curl, CURLOPT_TRANSFER_ENCODING, true);
|
|
|
c342a4 |
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);
|
|
|
c342a4 |
- curl_easy_setopt(curl, CURLOPT_VERBOSE, true);
|
|
|
c342a4 |
- curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, _curl_trace);
|
|
|
c342a4 |
-
|
|
|
c342a4 |
- CURLcode res = curl_easy_perform(curl);
|
|
|
c342a4 |
+ CURLcode res;
|
|
|
c342a4 |
+
|
|
|
c342a4 |
+ res = curl_easy_setopt(curl, CURLOPT_URL, url);
|
|
|
c342a4 |
+ if (res != 0) {
|
|
|
c342a4 |
+ oscap_seterr(OSCAP_EFAMILY_NET, "Failed to set CURLOPT_URL to '%s': %s", url, curl_easy_strerror(res));
|
|
|
c342a4 |
+ return NULL;
|
|
|
c342a4 |
+ }
|
|
|
c342a4 |
+
|
|
|
c342a4 |
+ res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_memory_callback);
|
|
|
c342a4 |
+ if (res != 0) {
|
|
|
c342a4 |
+ oscap_seterr(OSCAP_EFAMILY_NET, "Failed to set CURLOPT_WRITEFUNCTION to write_to_memory_callback: %s", curl_easy_strerror(res));
|
|
|
c342a4 |
+ return NULL;
|
|
|
c342a4 |
+ }
|
|
|
c342a4 |
+
|
|
|
c342a4 |
+ res = curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
|
|
|
c342a4 |
+ if (res != 0) {
|
|
|
c342a4 |
+ oscap_seterr(OSCAP_EFAMILY_NET, "Failed to set CURLOPT_ACCEPT_ENCODING to an empty string: %s", curl_easy_strerror(res));
|
|
|
c342a4 |
+ return NULL;
|
|
|
c342a4 |
+ }
|
|
|
c342a4 |
+
|
|
|
c342a4 |
+ res = curl_easy_setopt(curl, CURLOPT_TRANSFER_ENCODING, true);
|
|
|
c342a4 |
+ if (res != 0) {
|
|
|
c342a4 |
+ oscap_seterr(OSCAP_EFAMILY_NET, "Failed to set CURLOPT_TRANSFER_ENCODING to true: %s", curl_easy_strerror(res));
|
|
|
c342a4 |
+ return NULL;
|
|
|
c342a4 |
+ }
|
|
|
c342a4 |
+
|
|
|
c342a4 |
+ res = curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);
|
|
|
c342a4 |
+ if (res != 0) {
|
|
|
c342a4 |
+ oscap_seterr(OSCAP_EFAMILY_NET, "Failed to set CURLOPT_FOLLOWLOCATION to true: %s", curl_easy_strerror(res));
|
|
|
c342a4 |
+ return NULL;
|
|
|
c342a4 |
+ }
|
|
|
c342a4 |
+
|
|
|
c342a4 |
+ res = curl_easy_setopt(curl, CURLOPT_VERBOSE, true);
|
|
|
c342a4 |
+ if (res != 0) {
|
|
|
c342a4 |
+ oscap_seterr(OSCAP_EFAMILY_NET, "Failed to set CURLOPT_VERBOSE to true: %s", curl_easy_strerror(res));
|
|
|
c342a4 |
+ return NULL;
|
|
|
c342a4 |
+ }
|
|
|
c342a4 |
+
|
|
|
c342a4 |
+ res = curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, _curl_trace);
|
|
|
c342a4 |
+ if (res != 0) {
|
|
|
c342a4 |
+ oscap_seterr(OSCAP_EFAMILY_NET, "Failed to set CURLOPT_DEBUGFUNCTION to _curl_trace: %s", curl_easy_strerror(res));
|
|
|
c342a4 |
+ return NULL;
|
|
|
c342a4 |
+ }
|
|
|
c342a4 |
+
|
|
|
c342a4 |
+ struct oscap_buffer *buffer = oscap_buffer_new();
|
|
|
c342a4 |
+ res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer);
|
|
|
c342a4 |
+ if (res != 0) {
|
|
|
c342a4 |
+ oscap_seterr(OSCAP_EFAMILY_NET, "Failed to set CURLOPT_WRITEDATA as buffer: %s", curl_easy_strerror(res));
|
|
|
c342a4 |
+ oscap_buffer_free(buffer);
|
|
|
c342a4 |
+ return NULL;
|
|
|
c342a4 |
+ }
|
|
|
c342a4 |
+
|
|
|
c342a4 |
+ res = curl_easy_perform(curl);
|
|
|
c342a4 |
curl_easy_cleanup(curl);
|
|
|
c342a4 |
|
|
|
c342a4 |
if (res != 0) {
|
|
|
c342a4 |
|
|
|
c342a4 |
From 34af1348b6ff6e4710aeb6e383b1a50c4751c16e Mon Sep 17 00:00:00 2001
|
|
|
c342a4 |
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
|
|
|
c342a4 |
Date: Mon, 26 Oct 2020 11:12:04 +0100
|
|
|
c342a4 |
Subject: [PATCH 2/2] Add curl_easy_cleanup everywhere
|
|
|
c342a4 |
|
|
|
c342a4 |
---
|
|
|
c342a4 |
src/common/oscap_acquire.c | 8 ++++++++
|
|
|
c342a4 |
1 file changed, 8 insertions(+)
|
|
|
c342a4 |
|
|
|
c342a4 |
diff --git a/src/common/oscap_acquire.c b/src/common/oscap_acquire.c
|
|
|
c342a4 |
index 34a92fa19..cd9bfc36f 100644
|
|
|
c342a4 |
--- a/src/common/oscap_acquire.c
|
|
|
c342a4 |
+++ b/src/common/oscap_acquire.c
|
|
|
c342a4 |
@@ -330,42 +330,49 @@ char* oscap_acquire_url_download(const char *url, size_t* memory_size)
|
|
|
c342a4 |
|
|
|
c342a4 |
res = curl_easy_setopt(curl, CURLOPT_URL, url);
|
|
|
c342a4 |
if (res != 0) {
|
|
|
c342a4 |
+ curl_easy_cleanup(curl);
|
|
|
c342a4 |
oscap_seterr(OSCAP_EFAMILY_NET, "Failed to set CURLOPT_URL to '%s': %s", url, curl_easy_strerror(res));
|
|
|
c342a4 |
return NULL;
|
|
|
c342a4 |
}
|
|
|
c342a4 |
|
|
|
c342a4 |
res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_memory_callback);
|
|
|
c342a4 |
if (res != 0) {
|
|
|
c342a4 |
+ curl_easy_cleanup(curl);
|
|
|
c342a4 |
oscap_seterr(OSCAP_EFAMILY_NET, "Failed to set CURLOPT_WRITEFUNCTION to write_to_memory_callback: %s", curl_easy_strerror(res));
|
|
|
c342a4 |
return NULL;
|
|
|
c342a4 |
}
|
|
|
c342a4 |
|
|
|
c342a4 |
res = curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
|
|
|
c342a4 |
if (res != 0) {
|
|
|
c342a4 |
+ curl_easy_cleanup(curl);
|
|
|
c342a4 |
oscap_seterr(OSCAP_EFAMILY_NET, "Failed to set CURLOPT_ACCEPT_ENCODING to an empty string: %s", curl_easy_strerror(res));
|
|
|
c342a4 |
return NULL;
|
|
|
c342a4 |
}
|
|
|
c342a4 |
|
|
|
c342a4 |
res = curl_easy_setopt(curl, CURLOPT_TRANSFER_ENCODING, true);
|
|
|
c342a4 |
if (res != 0) {
|
|
|
c342a4 |
+ curl_easy_cleanup(curl);
|
|
|
c342a4 |
oscap_seterr(OSCAP_EFAMILY_NET, "Failed to set CURLOPT_TRANSFER_ENCODING to true: %s", curl_easy_strerror(res));
|
|
|
c342a4 |
return NULL;
|
|
|
c342a4 |
}
|
|
|
c342a4 |
|
|
|
c342a4 |
res = curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);
|
|
|
c342a4 |
if (res != 0) {
|
|
|
c342a4 |
+ curl_easy_cleanup(curl);
|
|
|
c342a4 |
oscap_seterr(OSCAP_EFAMILY_NET, "Failed to set CURLOPT_FOLLOWLOCATION to true: %s", curl_easy_strerror(res));
|
|
|
c342a4 |
return NULL;
|
|
|
c342a4 |
}
|
|
|
c342a4 |
|
|
|
c342a4 |
res = curl_easy_setopt(curl, CURLOPT_VERBOSE, true);
|
|
|
c342a4 |
if (res != 0) {
|
|
|
c342a4 |
+ curl_easy_cleanup(curl);
|
|
|
c342a4 |
oscap_seterr(OSCAP_EFAMILY_NET, "Failed to set CURLOPT_VERBOSE to true: %s", curl_easy_strerror(res));
|
|
|
c342a4 |
return NULL;
|
|
|
c342a4 |
}
|
|
|
c342a4 |
|
|
|
c342a4 |
res = curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, _curl_trace);
|
|
|
c342a4 |
if (res != 0) {
|
|
|
c342a4 |
+ curl_easy_cleanup(curl);
|
|
|
c342a4 |
oscap_seterr(OSCAP_EFAMILY_NET, "Failed to set CURLOPT_DEBUGFUNCTION to _curl_trace: %s", curl_easy_strerror(res));
|
|
|
c342a4 |
return NULL;
|
|
|
c342a4 |
}
|
|
|
c342a4 |
@@ -373,6 +380,7 @@ char* oscap_acquire_url_download(const char *url, size_t* memory_size)
|
|
|
c342a4 |
struct oscap_buffer *buffer = oscap_buffer_new();
|
|
|
c342a4 |
res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer);
|
|
|
c342a4 |
if (res != 0) {
|
|
|
c342a4 |
+ curl_easy_cleanup(curl);
|
|
|
c342a4 |
oscap_seterr(OSCAP_EFAMILY_NET, "Failed to set CURLOPT_WRITEDATA as buffer: %s", curl_easy_strerror(res));
|
|
|
c342a4 |
oscap_buffer_free(buffer);
|
|
|
c342a4 |
return NULL;
|