Fix coverity issues

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
This commit is contained in:
Fabiano Fidêncio 2019-06-03 10:17:04 +02:00
parent b5d6ac68ff
commit 943432a243
5 changed files with 207 additions and 2 deletions

View File

@ -0,0 +1,53 @@
From ab1b0bf0f3611b556627f42e5accb1063acd91cc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
Date: Mon, 20 May 2019 14:19:01 +0200
Subject: [PATCH 1/3] import: Don't call unlink(NULL)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Although `man 3 unlink` doesn't mention what should be the unlink()
behaviour when NULL is passed to it, both coverity and clang complains
about that.
Error: FORWARD_NULL (CWE-476):
osinfo-db-tools-1.5.0/tools/osinfo-db-import.c:157: var_compare_op:
Comparing "*source_file" to null implies that "*source_file" might be
null.
osinfo-db-tools-1.5.0/tools/osinfo-db-import.c:181: var_deref_model:
Passing null pointer "*source_file" to "unlink", which dereferences it.
# 179| g_error_free(err);
# 180| if (ret != 0)
# 181|-> unlink(*source_file);
# 182|
# 183| return ret;
Error: CLANG_WARNING:
osinfo-db-tools-1.5.0/tools/osinfo-db-import.c:181:9: warning: Null
pointer passed as an argument to a 'nonnull' parameter
# unlink(*source_file);
# ^
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
(cherry picked from commit 07be7309d830419c27ec65c76905d1e23219f480)
---
tools/osinfo-db-import.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/osinfo-db-import.c b/tools/osinfo-db-import.c
index 920f71b..11e68ae 100644
--- a/tools/osinfo-db-import.c
+++ b/tools/osinfo-db-import.c
@@ -177,7 +177,7 @@ osinfo_db_import_download_file(GFile *file,
g_object_unref(out);
if (err != NULL)
g_error_free(err);
- if (ret != 0)
+ if (ret != 0 && *source_file != NULL)
unlink(*source_file);
return ret;
--
2.21.0

View File

@ -0,0 +1,62 @@
From 125f04cb6d742fb13f691cfbff54437014a399bd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
Date: Mon, 20 May 2019 14:25:34 +0200
Subject: [PATCH 2/3] export: Remove unused variable
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
err is declared, set to NULL, but never used in
osinfo_db_export_create().
Error: DEADCODE (CWE-561):
osinfo-db-tools-1.5.0/tools/osinfo-db-export.c:410: assignment:
Assigning: "err" = "NULL".
osinfo-db-tools-1.5.0/tools/osinfo-db-export.c:448: null: At condition
"err", the value of "err" must be "NULL".
osinfo-db-tools-1.5.0/tools/osinfo-db-export.c:448: dead_error_condition:
The condition "err" cannot be true.
osinfo-db-tools-1.5.0/tools/osinfo-db-export.c:449: dead_error_line:
Execution cannot reach this statement: "g_error_free(err);".
osinfo-db-tools-1.5.0/tools/osinfo-db-export.c:449: effectively_constant:
Local variable "err" is assigned only once, to a constant value, making
it effectively constant throughout its scope. If this is not the intent,
examine the logic to see if there is a missing assigment that would make
"err" not remain constant.
# 447| archive_write_free(arc);
# 448| if (err)
# 449|-> g_error_free(err);
# 450| return ret;
# 451| }
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
(cherry picked from commit 2d747c637c78c000002f97880436d94cc08a6b5c)
---
tools/osinfo-db-export.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/tools/osinfo-db-export.c b/tools/osinfo-db-export.c
index 3137e1d..eef6688 100644
--- a/tools/osinfo-db-export.c
+++ b/tools/osinfo-db-export.c
@@ -407,7 +407,6 @@ static int osinfo_db_export_create(const gchar *prefix,
struct archive *arc;
int ret = -1;
int r;
- GError *err = NULL;
arc = archive_write_new();
@@ -445,8 +444,6 @@ static int osinfo_db_export_create(const gchar *prefix,
ret = 0;
cleanup:
archive_write_free(arc);
- if (err)
- g_error_free(err);
return ret;
}
--
2.21.0

View File

@ -0,0 +1,36 @@
From f4f65ea3e895eaab87af049300d2d69ba3d51c9f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
Date: Mon, 20 May 2019 14:28:22 +0200
Subject: [PATCH 3/3] validate: Don't leak "files"
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Error: CLANG_WARNING:
osinfo-db-tools-1.5.0/tools/osinfo-db-validate.c:319:9: warning:
Potential leak of memory pointed to by 'files'
# g_printerr("%s\n", error->message);
# ^
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
(cherry picked from commit 7ac63b928df3f445ede81cac0ade0ed6d810c3cb)
---
tools/osinfo-db-validate.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/osinfo-db-validate.c b/tools/osinfo-db-validate.c
index 0e28e1c..7fd87d2 100644
--- a/tools/osinfo-db-validate.c
+++ b/tools/osinfo-db-validate.c
@@ -327,6 +327,7 @@ gint main(gint argc, gchar **argv)
g_object_unref(schema);
if (dir)
g_object_unref(dir);
+ g_free(files);
g_clear_error(&error);
g_option_context_free(context);
--
2.21.0

View File

@ -0,0 +1,43 @@
From 66cdd50832a99e175079bfb36a321fd9499c6f0e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
Date: Wed, 22 May 2019 18:06:28 +0200
Subject: [PATCH] import: Don't call unlink(NULL) in _import_extract()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Similarly to the issue fixed by ae52b0fbc, here we're also potentially
passing NULL to unlink().
Error: FORWARD_NULL (CWE-476):
osinfo-db-tools-1.5.0/tools/osinfo-db-import.c:332: var_compare_op: Comparing "source_file" to null implies that "source_file" might be null.
osinfo-db-tools-1.5.0/tools/osinfo-db-import.c:374: var_deref_model: Passing null pointer "source_file" to "unlink", which dereferences it.
# 372| g_object_unref(file);
# 373| if (!file_is_native)
# 374|-> unlink(source_file);
# 375| g_free(source_file);
# 376| return ret;
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
(cherry picked from commit 69eb33ad4207c76c0738bfa00b40c97892bab0ad)
---
tools/osinfo-db-import.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/osinfo-db-import.c b/tools/osinfo-db-import.c
index 11e68ae..675961d 100644
--- a/tools/osinfo-db-import.c
+++ b/tools/osinfo-db-import.c
@@ -370,7 +370,7 @@ static int osinfo_db_import_extract(GFile *target,
archive_read_free(arc);
if (file)
g_object_unref(file);
- if (!file_is_native)
+ if (!file_is_native && source_file != NULL)
unlink(source_file);
g_free(source_file);
return ret;
--
2.21.0

View File

@ -3,12 +3,20 @@
Summary: Tools for managing the osinfo database
Name: osinfo-db-tools
Version: 1.5.0
Release: 1%{?dist}
Release: 2%{?dist}
License: GPLv2+
Source: https://releases.pagure.io/libosinfo/%{name}-%{version}.tar.gz
URL: http://libosinfo.org/
### Patches ###
Patch0001: 0001-import-Don-t-call-unlink-NULL.patch
Patch0002: 0002-export-Remove-unused-variable.patch
Patch0003: 0003-validate-Don-t-leak-files.patch
Patch0004: 0004-import-Don-t-call-unlink-NULL-in-_import_extract.patch
BuildRequires: gcc
BuildRequires: gettext-devel
BuildRequires: git
BuildRequires: glib2-devel
BuildRequires: libxml2-devel >= 2.6.0
BuildRequires: libxslt-devel >= 1.0.0
@ -25,7 +33,7 @@ This package provides tools for managing the osinfo database of
information about operating systems for use with virtualization
%prep
%setup -q
%autosetup -S git
%build
%configure
@ -56,6 +64,9 @@ fi
%{_mandir}/man1/osinfo-db-validate.1*
%changelog
* Mon Jun 03 2019 Fabiano Fidêncio <fidencio@redhat.com> -1.5.0-2
- Fix coverity issues
* Thu May 09 2019 Fabiano Fidêncio <fidencio@redhat.com> - 1.5.0-1
- Update to 1.5.0 release