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(a)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