Blame SOURCES/0001-db-Avoid-dereference-of-null-pointer.patch

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