|
|
3ea492 |
From fd9d39cf19084dd4244943a3b27ee0a33805f76d Mon Sep 17 00:00:00 2001
|
|
|
3ea492 |
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
|
|
|
3ea492 |
Date: Mon, 21 Jun 2021 15:04:51 +0200
|
|
|
3ea492 |
Subject: [PATCH 1/2] Fix important covscan warnings
|
|
|
3ea492 |
|
|
|
3ea492 |
- covscan thinks we are leaking storage from `g_strndup` so be more
|
|
|
3ea492 |
explicit that `g_strstrip` is in place.
|
|
|
3ea492 |
---
|
|
|
3ea492 |
librepo/downloader.c | 5 ++++-
|
|
|
3ea492 |
1 file changed, 4 insertions(+), 1 deletion(-)
|
|
|
3ea492 |
|
|
|
3ea492 |
diff --git a/librepo/downloader.c b/librepo/downloader.c
|
|
|
3ea492 |
index c5278fbc..f4e8ba2a 100644
|
|
|
3ea492 |
--- a/librepo/downloader.c
|
|
|
3ea492 |
+++ b/librepo/downloader.c
|
|
|
3ea492 |
@@ -494,7 +494,10 @@ lr_headercb(void *ptr, size_t size, size_t nmemb, void *userdata)
|
|
|
3ea492 |
return lr_zckheadercb(ptr, size, nmemb, userdata);
|
|
|
3ea492 |
#endif /* WITH_ZCHUNK */
|
|
|
3ea492 |
|
|
|
3ea492 |
- char *header = g_strstrip(g_strndup(ptr, size*nmemb));
|
|
|
3ea492 |
+ char *header = g_strndup(ptr, size*nmemb);
|
|
|
3ea492 |
+ // strips in place
|
|
|
3ea492 |
+ g_strstrip(header);
|
|
|
3ea492 |
+
|
|
|
3ea492 |
gint64 expected = lrtarget->target->expectedsize;
|
|
|
3ea492 |
|
|
|
3ea492 |
if (state == LR_HCS_DEFAULT) {
|
|
|
3ea492 |
|
|
|
3ea492 |
From 5a9e9e99c64e2dc1d181fa14cf348c7f51611a7a Mon Sep 17 00:00:00 2001
|
|
|
3ea492 |
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
|
|
|
3ea492 |
Date: Mon, 21 Jun 2021 15:05:13 +0200
|
|
|
3ea492 |
Subject: [PATCH 2/2] Fix covscan warnings
|
|
|
3ea492 |
|
|
|
3ea492 |
- remove unused code
|
|
|
3ea492 |
- missing return value checks
|
|
|
3ea492 |
- use mkstemp just like other tests
|
|
|
3ea492 |
---
|
|
|
3ea492 |
librepo/handle.c | 12 +++++++++---
|
|
|
3ea492 |
tests/test_downloader.c | 40 ++++++++++++++++++++--------------------
|
|
|
3ea492 |
tests/test_repoconf.c | 22 +++-------------------
|
|
|
3ea492 |
3 files changed, 32 insertions(+), 42 deletions(-)
|
|
|
3ea492 |
|
|
|
3ea492 |
diff --git a/librepo/handle.c b/librepo/handle.c
|
|
|
3ea492 |
index 8ac7234c..2c23ed09 100644
|
|
|
3ea492 |
--- a/librepo/handle.c
|
|
|
3ea492 |
+++ b/librepo/handle.c
|
|
|
3ea492 |
@@ -628,7 +628,7 @@ lr_handle_setopt(LrHandle *handle,
|
|
|
3ea492 |
"Value of LRO_LOWSPEEDTIME is too low.");
|
|
|
3ea492 |
ret = FALSE;
|
|
|
3ea492 |
} else {
|
|
|
3ea492 |
- curl_easy_setopt(c_h, CURLOPT_LOW_SPEED_TIME, val_long);
|
|
|
3ea492 |
+ c_rc = curl_easy_setopt(c_h, CURLOPT_LOW_SPEED_TIME, val_long);
|
|
|
3ea492 |
handle->lowspeedtime = val_long;
|
|
|
3ea492 |
}
|
|
|
3ea492 |
|
|
|
3ea492 |
@@ -648,7 +648,7 @@ lr_handle_setopt(LrHandle *handle,
|
|
|
3ea492 |
val_long, handle->maxspeed);
|
|
|
3ea492 |
ret = FALSE;
|
|
|
3ea492 |
} else {
|
|
|
3ea492 |
- curl_easy_setopt(c_h, CURLOPT_LOW_SPEED_LIMIT, val_long);
|
|
|
3ea492 |
+ c_rc = curl_easy_setopt(c_h, CURLOPT_LOW_SPEED_LIMIT, val_long);
|
|
|
3ea492 |
handle->lowspeedlimit = val_long;
|
|
|
3ea492 |
}
|
|
|
3ea492 |
|
|
|
3ea492 |
@@ -885,7 +885,13 @@ lr_yum_download_url_retry(int attempts, LrHandle *lr_handle, const char *url,
|
|
|
3ea492 |
|
|
|
3ea492 |
g_debug("%s: Attempt #%d to download %s failed: %s",
|
|
|
3ea492 |
__func__, i, url, (*err)->message);
|
|
|
3ea492 |
- ftruncate(fd, 0);
|
|
|
3ea492 |
+
|
|
|
3ea492 |
+ if (ftruncate(fd, 0) < 0) {
|
|
|
3ea492 |
+ g_set_error(err, LR_DOWNLOADER_ERROR, LRE_IO,
|
|
|
3ea492 |
+ "ftruncate() failed: %s", g_strerror(errno));
|
|
|
3ea492 |
+ return FALSE;
|
|
|
3ea492 |
+ }
|
|
|
3ea492 |
+
|
|
|
3ea492 |
g_clear_error (err);
|
|
|
3ea492 |
}
|
|
|
3ea492 |
}
|
|
|
3ea492 |
diff --git a/tests/test_downloader.c b/tests/test_downloader.c
|
|
|
3ea492 |
index 3a1c60f4..e6155105 100644
|
|
|
3ea492 |
--- a/tests/test_downloader.c
|
|
|
3ea492 |
+++ b/tests/test_downloader.c
|
|
|
3ea492 |
@@ -46,7 +46,7 @@ START_TEST(test_downloader_single_file)
|
|
|
3ea492 |
fail_if(handle == NULL);
|
|
|
3ea492 |
|
|
|
3ea492 |
char *urls[] = {"http://www.google.com", NULL};
|
|
|
3ea492 |
- lr_handle_setopt(handle, NULL, LRO_URLS, urls);
|
|
|
3ea492 |
+ fail_if(!lr_handle_setopt(handle, NULL, LRO_URLS, urls));
|
|
|
3ea492 |
lr_handle_prepare_internal_mirrorlist(handle, FALSE, &tmp_err);
|
|
|
3ea492 |
fail_if(tmp_err);
|
|
|
3ea492 |
|
|
|
3ea492 |
@@ -55,8 +55,7 @@ START_TEST(test_downloader_single_file)
|
|
|
3ea492 |
|
|
|
3ea492 |
tmpfn1 = lr_pathconcat(test_globals.tmpdir, "single_file_XXXXXX", NULL);
|
|
|
3ea492 |
|
|
|
3ea492 |
- mktemp(tmpfn1);
|
|
|
3ea492 |
- fd1 = open(tmpfn1, O_RDWR|O_CREAT|O_TRUNC, 0666);
|
|
|
3ea492 |
+ fd1 = mkstemp(tmpfn1);
|
|
|
3ea492 |
lr_free(tmpfn1);
|
|
|
3ea492 |
fail_if(fd1 < 0);
|
|
|
3ea492 |
|
|
|
3ea492 |
@@ -86,6 +85,7 @@ START_TEST(test_downloader_single_file)
|
|
|
3ea492 |
}
|
|
|
3ea492 |
|
|
|
3ea492 |
g_slist_free_full(list, (GDestroyNotify) lr_downloadtarget_free);
|
|
|
3ea492 |
+ close(fd1);
|
|
|
3ea492 |
}
|
|
|
3ea492 |
END_TEST
|
|
|
3ea492 |
|
|
|
3ea492 |
@@ -102,8 +102,7 @@ START_TEST(test_downloader_single_file_2)
|
|
|
3ea492 |
|
|
|
3ea492 |
tmpfn1 = lr_pathconcat(test_globals.tmpdir, "single_file_2_XXXXXX", NULL);
|
|
|
3ea492 |
|
|
|
3ea492 |
- mktemp(tmpfn1);
|
|
|
3ea492 |
- fd1 = open(tmpfn1, O_RDWR|O_CREAT|O_TRUNC, 0666);
|
|
|
3ea492 |
+ fd1 = mkstemp(tmpfn1);
|
|
|
3ea492 |
lr_free(tmpfn1);
|
|
|
3ea492 |
fail_if(fd1 < 0);
|
|
|
3ea492 |
|
|
|
3ea492 |
@@ -131,6 +130,7 @@ START_TEST(test_downloader_single_file_2)
|
|
|
3ea492 |
}
|
|
|
3ea492 |
|
|
|
3ea492 |
g_slist_free_full(list, (GDestroyNotify) lr_downloadtarget_free);
|
|
|
3ea492 |
+ close(fd1);
|
|
|
3ea492 |
}
|
|
|
3ea492 |
END_TEST
|
|
|
3ea492 |
|
|
|
3ea492 |
@@ -151,7 +151,7 @@ START_TEST(test_downloader_two_files)
|
|
|
3ea492 |
fail_if(handle == NULL);
|
|
|
3ea492 |
|
|
|
3ea492 |
char *urls[] = {"http://www.google.com", NULL};
|
|
|
3ea492 |
- lr_handle_setopt(handle, NULL, LRO_URLS, urls);
|
|
|
3ea492 |
+ fail_if(!lr_handle_setopt(handle, NULL, LRO_URLS, urls));
|
|
|
3ea492 |
lr_handle_prepare_internal_mirrorlist(handle, FALSE, &tmp_err);
|
|
|
3ea492 |
fail_if(tmp_err);
|
|
|
3ea492 |
|
|
|
3ea492 |
@@ -160,10 +160,8 @@ START_TEST(test_downloader_two_files)
|
|
|
3ea492 |
tmpfn1 = lr_pathconcat(test_globals.tmpdir, "single_file_1_XXXXXX", NULL);
|
|
|
3ea492 |
tmpfn2 = lr_pathconcat(test_globals.tmpdir, "single_file_2_XXXXXX", NULL);
|
|
|
3ea492 |
|
|
|
3ea492 |
- mktemp(tmpfn1);
|
|
|
3ea492 |
- mktemp(tmpfn2);
|
|
|
3ea492 |
- fd1 = open(tmpfn1, O_RDWR|O_CREAT|O_TRUNC, 0666);
|
|
|
3ea492 |
- fd2 = open(tmpfn2, O_RDWR|O_CREAT|O_TRUNC, 0666);
|
|
|
3ea492 |
+ fd1 = mkstemp(tmpfn1);
|
|
|
3ea492 |
+ fd2 = mkstemp(tmpfn2);
|
|
|
3ea492 |
lr_free(tmpfn1);
|
|
|
3ea492 |
lr_free(tmpfn2);
|
|
|
3ea492 |
fail_if(fd1 < 0);
|
|
|
3ea492 |
@@ -200,6 +198,8 @@ START_TEST(test_downloader_two_files)
|
|
|
3ea492 |
}
|
|
|
3ea492 |
|
|
|
3ea492 |
g_slist_free_full(list, (GDestroyNotify) lr_downloadtarget_free);
|
|
|
3ea492 |
+ close(fd1);
|
|
|
3ea492 |
+ close(fd2);
|
|
|
3ea492 |
}
|
|
|
3ea492 |
END_TEST
|
|
|
3ea492 |
|
|
|
3ea492 |
@@ -220,7 +220,7 @@ START_TEST(test_downloader_three_files_with_error)
|
|
|
3ea492 |
fail_if(handle == NULL);
|
|
|
3ea492 |
|
|
|
3ea492 |
char *urls[] = {"http://www.google.com", NULL};
|
|
|
3ea492 |
- lr_handle_setopt(handle, NULL, LRO_URLS, urls);
|
|
|
3ea492 |
+ fail_if(!lr_handle_setopt(handle, NULL, LRO_URLS, urls));
|
|
|
3ea492 |
lr_handle_prepare_internal_mirrorlist(handle, FALSE, &tmp_err);
|
|
|
3ea492 |
fail_if(tmp_err);
|
|
|
3ea492 |
|
|
|
3ea492 |
@@ -230,12 +230,9 @@ START_TEST(test_downloader_three_files_with_error)
|
|
|
3ea492 |
tmpfn2 = lr_pathconcat(test_globals.tmpdir, "single_file_2_XXXXXX", NULL);
|
|
|
3ea492 |
tmpfn3 = lr_pathconcat(test_globals.tmpdir, "single_file_3_XXXXXX", NULL);
|
|
|
3ea492 |
|
|
|
3ea492 |
- mktemp(tmpfn1);
|
|
|
3ea492 |
- mktemp(tmpfn2);
|
|
|
3ea492 |
- mktemp(tmpfn3);
|
|
|
3ea492 |
- fd1 = open(tmpfn1, O_RDWR|O_CREAT|O_TRUNC, 0666);
|
|
|
3ea492 |
- fd2 = open(tmpfn2, O_RDWR|O_CREAT|O_TRUNC, 0666);
|
|
|
3ea492 |
- fd3 = open(tmpfn3, O_RDWR|O_CREAT|O_TRUNC, 0666);
|
|
|
3ea492 |
+ fd1 = mkstemp(tmpfn1);
|
|
|
3ea492 |
+ fd2 = mkstemp(tmpfn2);
|
|
|
3ea492 |
+ fd3 = mkstemp(tmpfn3);
|
|
|
3ea492 |
lr_free(tmpfn1);
|
|
|
3ea492 |
lr_free(tmpfn2);
|
|
|
3ea492 |
lr_free(tmpfn3);
|
|
|
3ea492 |
@@ -290,6 +287,9 @@ START_TEST(test_downloader_three_files_with_error)
|
|
|
3ea492 |
}
|
|
|
3ea492 |
|
|
|
3ea492 |
g_slist_free_full(list, (GDestroyNotify) lr_downloadtarget_free);
|
|
|
3ea492 |
+ close(fd1);
|
|
|
3ea492 |
+ close(fd2);
|
|
|
3ea492 |
+ close(fd3);
|
|
|
3ea492 |
}
|
|
|
3ea492 |
END_TEST
|
|
|
3ea492 |
|
|
|
3ea492 |
@@ -331,7 +331,7 @@ START_TEST(test_downloader_checksum)
|
|
|
3ea492 |
fail_if(handle == NULL);
|
|
|
3ea492 |
|
|
|
3ea492 |
char *urls[] = {"file:///", NULL};
|
|
|
3ea492 |
- lr_handle_setopt(handle, NULL, LRO_URLS, urls);
|
|
|
3ea492 |
+ fail_if(!lr_handle_setopt(handle, NULL, LRO_URLS, urls));
|
|
|
3ea492 |
lr_handle_prepare_internal_mirrorlist(handle, FALSE, &tmp_err);
|
|
|
3ea492 |
fail_if(tmp_err);
|
|
|
3ea492 |
|
|
|
3ea492 |
@@ -340,8 +340,7 @@ START_TEST(test_downloader_checksum)
|
|
|
3ea492 |
|
|
|
3ea492 |
tmpfn1 = lr_pathconcat(test_globals.tmpdir, "single_file_XXXXXX", NULL);
|
|
|
3ea492 |
|
|
|
3ea492 |
- mktemp(tmpfn1);
|
|
|
3ea492 |
- fd1 = open(tmpfn1, O_RDWR|O_CREAT|O_TRUNC, 0666);
|
|
|
3ea492 |
+ fd1 = mkstemp(tmpfn1);
|
|
|
3ea492 |
lr_free(tmpfn1);
|
|
|
3ea492 |
fail_if(fd1 < 0);
|
|
|
3ea492 |
|
|
|
3ea492 |
@@ -382,6 +381,7 @@ START_TEST(test_downloader_checksum)
|
|
|
3ea492 |
}
|
|
|
3ea492 |
|
|
|
3ea492 |
g_slist_free_full(list, (GDestroyNotify) lr_downloadtarget_free);
|
|
|
3ea492 |
+ close(fd1);
|
|
|
3ea492 |
}
|
|
|
3ea492 |
}
|
|
|
3ea492 |
END_TEST
|
|
|
3ea492 |
diff --git a/tests/test_repoconf.c b/tests/test_repoconf.c
|
|
|
3ea492 |
index 8a56b666..5c85047e 100644
|
|
|
3ea492 |
--- a/tests/test_repoconf.c
|
|
|
3ea492 |
+++ b/tests/test_repoconf.c
|
|
|
3ea492 |
@@ -33,22 +33,6 @@ repoconf_assert_true(LrYumRepoConf *repoconf,
|
|
|
3ea492 |
#define conf_assert_true(option) \
|
|
|
3ea492 |
repoconf_assert_true(conf, (option))
|
|
|
3ea492 |
|
|
|
3ea492 |
-static void
|
|
|
3ea492 |
-repoconf_assert_false(LrYumRepoConf *repoconf,
|
|
|
3ea492 |
- LrYumRepoConfOption option)
|
|
|
3ea492 |
-{
|
|
|
3ea492 |
- ck_assert(1);
|
|
|
3ea492 |
- long val = 1L;
|
|
|
3ea492 |
- _cleanup_error_free_ GError *tmp_err = NULL;
|
|
|
3ea492 |
- gboolean ret = lr_yum_repoconf_getinfo(repoconf, &tmp_err, option, &val;;
|
|
|
3ea492 |
- ck_assert(!tmp_err);
|
|
|
3ea492 |
- ck_assert(ret);
|
|
|
3ea492 |
- ck_assert_msg(!val, "Not a 0 (False) value (Option %d)", option);
|
|
|
3ea492 |
-}
|
|
|
3ea492 |
-
|
|
|
3ea492 |
-#define conf_assert_false(option) \
|
|
|
3ea492 |
- repoconf_assert_false(conf, (option))
|
|
|
3ea492 |
-
|
|
|
3ea492 |
static void
|
|
|
3ea492 |
repoconf_assert_na(LrYumRepoConf *repoconf,
|
|
|
3ea492 |
LrYumRepoConfOption option)
|
|
|
3ea492 |
@@ -509,7 +493,7 @@ END_TEST
|
|
|
3ea492 |
|
|
|
3ea492 |
START_TEST(test_write_repoconf)
|
|
|
3ea492 |
{
|
|
|
3ea492 |
- _cleanup_fd_close_ int rc = -1;
|
|
|
3ea492 |
+ _cleanup_fd_close_ int fd = -1;
|
|
|
3ea492 |
gboolean ret;
|
|
|
3ea492 |
LrYumRepoConfs *confs;
|
|
|
3ea492 |
LrYumRepoConf * conf;
|
|
|
3ea492 |
@@ -519,8 +503,8 @@ START_TEST(test_write_repoconf)
|
|
|
3ea492 |
_cleanup_error_free_ GError *tmp_err = NULL;
|
|
|
3ea492 |
|
|
|
3ea492 |
// Create a temporary file
|
|
|
3ea492 |
- rc = mkstemp(tmpfn);
|
|
|
3ea492 |
- fail_if(rc == -1);
|
|
|
3ea492 |
+ fd = mkstemp(tmpfn);
|
|
|
3ea492 |
+ fail_if(fd == -1);
|
|
|
3ea492 |
|
|
|
3ea492 |
// Create reconfs with one repoconf with one id (one section)
|
|
|
3ea492 |
confs = lr_yum_repoconfs_init();
|