[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libosinfo] [libosinfo PATCH] tools, detect: Check for NULL variants



Both trees & medias may return NULL in case no os-variant was found.
Let's check for this and avoid a segmentation fault on calling
osinfo_list_get_length() with a NULL argument.

Signed-off-by: Fabiano Fidêncio <fidencio redhat com>
---
 tools/osinfo-detect.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/osinfo-detect.c b/tools/osinfo-detect.c
index feb9978..9529ef5 100644
--- a/tools/osinfo-detect.c
+++ b/tools/osinfo-detect.c
@@ -137,10 +137,12 @@ static void print_media(OsinfoMedia *media)
     } else {
         OsinfoOsVariantList *variants;
         const gchar *name;
-        guint num_variants;
+        guint num_variants = 0;
 
         variants = osinfo_media_get_os_variants(media);
-        num_variants = osinfo_list_get_length(OSINFO_LIST(variants));
+        if (variants != NULL)
+            num_variants = osinfo_list_get_length(OSINFO_LIST(variants));
+
         if (num_variants == 1) {
             OsinfoEntity *variant;
 
@@ -206,10 +208,12 @@ static void print_tree(OsinfoTree *tree)
     } else {
         OsinfoOsVariantList *variants;
         const gchar *name;
-        guint num_variants;
+        guint num_variants = 0;
 
         variants = osinfo_tree_get_os_variants(tree);
-        num_variants = osinfo_list_get_length(OSINFO_LIST(variants));
+        if (variants != NULL)
+            num_variants = osinfo_list_get_length(OSINFO_LIST(variants));
+
         if (num_variants == 1) {
             OsinfoEntity *variant;
 
-- 
2.21.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]