[libosinfo PATCH 2/3] media, image, tree: Avoid critical errors when getting the os variants

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

 



When getting the os variant of media, image, or tree, let's ensure their
OS is not NULL* before calling osinfo_os_get_variant_list(). In case
it's NULL, let's just return NULL.

*: having a media, image, or tree with no OS set is a common case when
the user has been creating it manually.

https://gitlab.com/libosinfo/libosinfo/issues/25

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 osinfo/osinfo_image.c | 4 ++++
 osinfo/osinfo_media.c | 4 ++++
 osinfo/osinfo_tree.c  | 4 ++++
 3 files changed, 12 insertions(+)

diff --git a/osinfo/osinfo_image.c b/osinfo/osinfo_image.c
index fcde244..621ebf0 100644
--- a/osinfo/osinfo_image.c
+++ b/osinfo/osinfo_image.c
@@ -326,7 +326,11 @@ OsinfoOsVariantList *osinfo_image_get_os_variants(OsinfoImage *image)
     OsinfoFilter *filter;
 
     g_return_val_if_fail(OSINFO_IS_IMAGE(image), NULL);
+
     os = osinfo_image_get_os(image);
+    if (os == NULL)
+        return NULL;
+
     os_variants = osinfo_os_get_variant_list(os);
     g_object_unref(os);
 
diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index 4f86c2b..b1c14dd 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -1555,6 +1555,10 @@ OsinfoOsVariantList *osinfo_media_get_os_variants(OsinfoMedia *media)
     OsinfoFilter *filter;
 
     g_return_val_if_fail(OSINFO_IS_MEDIA(media), NULL);
+
+    if (media->priv->os == NULL)
+        return NULL;
+
     os = g_weak_ref_get(&media->priv->os);
     os_variants = osinfo_os_get_variant_list(os);
     g_object_unref(os);
diff --git a/osinfo/osinfo_tree.c b/osinfo/osinfo_tree.c
index 119216a..88a2d6e 100644
--- a/osinfo/osinfo_tree.c
+++ b/osinfo/osinfo_tree.c
@@ -978,7 +978,11 @@ OsinfoOsVariantList *osinfo_tree_get_os_variants(OsinfoTree *tree)
     OsinfoFilter *filter;
 
     g_return_val_if_fail(OSINFO_IS_TREE(tree), NULL);
+
     os = osinfo_tree_get_os(tree);
+    if (os == NULL)
+        return NULL;
+
     os_variants = osinfo_os_get_variant_list(os);
     g_object_unref(os);
 
-- 
2.20.1

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux