]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
network: fix crash when portgroup has no name
authorLaine Stump <laine@laine.org>
Wed, 28 Nov 2012 04:59:17 +0000 (23:59 -0500)
committerLaine Stump <laine@laine.org>
Wed, 28 Nov 2012 16:59:30 +0000 (11:59 -0500)
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=879473

The name attribute is required for portgroup elements (yes, the RNG
specifies that), and there is code in libvirt that assumes it is
non-null.  Unfortunately, the portgroup parsing function wasn't
checking for lack of portgroup. One adverse result of this was that
attempts to update a network by adding a portgroup with no name would
cause libvirtd to segfault. For example:

   virsh net-update default add portgroup "<portgroup default='yes'/>"

This patch causes virNetworkPortGroupParseXML to fail if no name is
specified, thus avoiding any later problems.

src/conf/network_conf.c

index 228951d4f255581977b369db74e0cfd6d4e81eed..6ce2e638bbedb7cf3ecd22f5f34a6dfa8d6e99bc 100644 (file)
@@ -1175,6 +1175,12 @@ virNetworkPortGroupParseXML(virPortGroupDefPtr def,
 
     /* grab raw data from XML */
     def->name = virXPathString("string(./@name)", ctxt);
+    if (!def->name) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("Missing required name attribute in portgroup"));
+        goto error;
+    }
+
     isDefault = virXPathString("string(./@default)", ctxt);
     def->isDefault = isDefault && STRCASEEQ(isDefault, "yes");