[libvirt] [libvirt-glib/libvirt-gconfig 17/17] gconfig, graphics: Avoid crash when gvir_config_object_new_from_xml() returns NULL

Christophe Fergeau cfergeau at redhat.com
Tue Sep 6 08:48:59 UTC 2016


On Thu, Apr 21, 2016 at 01:05:45PM +0200, Christophe Fergeau wrote:
> This issues is more widespread than that, it would be better to fix it
> everywhere in one go (maybe through a gvir_config_object_check_type() or
> something like this?)

I believe this patch should do for now (with runtime warnings). Since
I'm not sure how widespread _new_from_xml() use is, maybe it's enough
for now, and we can decide on the best way to handle a NULL return when
we start getting runtime warnings from that patch?


From 0b428df2d82b6e669b50a3c400716c3883f9fe9c Mon Sep 17 00:00:00 2001
From: Christophe Fergeau <cfergeau at redhat.com>
Date: Tue, 6 Sep 2016 10:30:58 +0200
Subject: [libvirt-glib] gconfig: Add precondition to
 gvir_config_object_get_xml_node()

This will catch (among other things) cases when
gvir_config_object_get_xml_node() is called with a NULL argument. Not
catching this could cause a crash later on in cases when
gvir_config_object_new_from_xml() is called and returns NULL, and then
we call gvir_config_object_get_attribute() on it.
Now this should be caught with runtime warnings so that the underlying
issue can be fixed.
---
 libvirt-gconfig/libvirt-gconfig-object.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c
index 6225de2..8cc4065 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -284,6 +284,8 @@ gvir_config_object_get_xml_doc(GVirConfigObject *config)
 G_GNUC_INTERNAL xmlNodePtr
 gvir_config_object_get_xml_node(GVirConfigObject *config)
 {
+    g_return_val_if_fail(GVIR_CONFIG_IS_OBJECT(config), NULL);
+
     return config->priv->node;
 }
 
-- 
2.7.4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20160906/c2ebde95/attachment-0001.sig>


More information about the libvir-list mailing list