libosinfo/SOURCES/0001-db-Avoid-dereference-of-null-pointer.patch
2021-09-09 20:39:47 +00:00

63 lines
2.2 KiB
Diff

From cb509ad153a35053e1e003d73fd0ece53bd2c3d8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
Date: Tue, 21 May 2019 13:01:26 +0200
Subject: [PATCH 1/3] db: Avoid dereference of null pointer
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
As any consumer of libosinfo API may pass NULL as the @matched argument
of compare_tree(), the current code could be dereferencing a NULL
pointer when calling `osinfo_tree_set_os()`.
In order to avoid doing so, let's set the os to the OsinfoTree at the
moment the @matched argument is set.
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
(cherry picked from commit 949ad5e05480470ba1a5913fbec538314807dfc2)
---
osinfo/osinfo_db.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c
index b7da2b7..c4cd1e4 100644
--- a/osinfo/osinfo_db.c
+++ b/osinfo/osinfo_db.c
@@ -790,6 +790,7 @@ static gboolean compare_tree(OsinfoTree *tree,
OsinfoTreeList *tree_list = osinfo_os_get_tree_list(os);
GList *trees = osinfo_list_get_elements(OSINFO_LIST(tree_list));
GList *tree_iter;
+ gboolean found = FALSE;
for (tree_iter = trees; tree_iter; tree_iter = tree_iter->next) {
OsinfoTree *os_tree = OSINFO_TREE(tree_iter->data);
@@ -820,8 +821,11 @@ static gboolean compare_tree(OsinfoTree *tree,
match_regex(os_treeinfo_version, treeinfo_version) &&
match_regex(os_treeinfo_arch, treeinfo_arch)) {
*ret_os = os;
- if (matched != NULL)
+ if (matched != NULL) {
*matched = os_tree;
+ osinfo_tree_set_os(*matched, *ret_os);
+ found = TRUE;
+ }
break;
}
}
@@ -829,10 +833,8 @@ static gboolean compare_tree(OsinfoTree *tree,
g_list_free(trees);
g_object_unref(tree_list);
- if (*ret_os != NULL) {
- osinfo_tree_set_os(*matched, *ret_os);
+ if (found)
return TRUE;
- }
}
return FALSE;
--
2.21.0