[libvirt] [libvirt-glib 1/3] Fix NULL deref when an attribute cannot be found

Christophe Fergeau cfergeau at redhat.com
Mon Mar 12 17:52:47 UTC 2012


When gvir_config_xml_get_attribute_content fails to find the
attribute that the caller is looking for, we will try to dereference
'attr' which is NULL in this case. This will cause a crash.
---
 libvirt-gconfig/libvirt-gconfig-helpers.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-helpers.c b/libvirt-gconfig/libvirt-gconfig-helpers.c
index 49c7f90..3790cab 100644
--- a/libvirt-gconfig/libvirt-gconfig-helpers.c
+++ b/libvirt-gconfig/libvirt-gconfig-helpers.c
@@ -254,10 +254,10 @@ gvir_config_xml_get_attribute_content(xmlNodePtr node, const char *attr_name)
             continue;
 
         if (strcmp (attr_name, (char *)attr->name) == 0)
-            break;
+            return attr->children->content;
     }
 
-    return attr->children->content;
+    return NULL;
 }
 
 G_GNUC_INTERNAL const char *
-- 
1.7.7.6




More information about the libvir-list mailing list