[libvirt] [libvirt-glib 19/20] gconfig: Add precondition to gvir_config_object_get_xml_node()

Christophe Fergeau cfergeau at redhat.com
Tue Oct 4 15:23:57 UTC 2016


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




More information about the libvir-list mailing list