]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: net: Correctly switch how to format address fields
authorPeter Krempa <pkrempa@redhat.com>
Thu, 21 Aug 2014 09:06:37 +0000 (11:06 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 21 Aug 2014 13:55:07 +0000 (15:55 +0200)
When formatting the forward mode addresses or interfaces the switch was
done based on the type of the network rather than of the type of the
individual <interface>/<address> element. In case a user would specify
an incorrect network type ("passhtrough") with <address> elements,
libvirtd would crash as it would attempt to format an <interface>.

Use the type of the individual element to format the XML.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1132347

src/conf/network_conf.c
tests/networkxml2xmlin/passthrough-address-crash.xml [new file with mode: 0644]
tests/networkxml2xmlout/passthrough-address-crash.xml [new file with mode: 0644]
tests/networkxml2xmltest.c

index 756b9dece68878231eec64c9a3671998d95d6765..dc25c6ead6b0bf8d8160d1686cfa9e15c81f7a6f 100644 (file)
@@ -2731,7 +2731,7 @@ virNetworkDefFormatBuf(virBufferPtr buf,
         if (def->forward.nifs &&
             (!def->forward.npfs || !(flags & VIR_NETWORK_XML_INACTIVE))) {
             for (i = 0; i < def->forward.nifs; i++) {
-                if (def->forward.type != VIR_NETWORK_FORWARD_HOSTDEV) {
+                if (def->forward.ifs[i].type == VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV) {
                     virBufferEscapeString(buf, "<interface dev='%s'",
                                           def->forward.ifs[i].device.dev);
                     if (!(flags & VIR_NETWORK_XML_INACTIVE) &&
@@ -2740,8 +2740,7 @@ virNetworkDefFormatBuf(virBufferPtr buf,
                                           def->forward.ifs[i].connections);
                     }
                     virBufferAddLit(buf, "/>\n");
-                }
-                else {
+                } else {
                     if (def->forward.ifs[i].type ==  VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_PCI) {
                         if (virDevicePCIAddressFormat(buf,
                                                       def->forward.ifs[i].device.pci,
diff --git a/tests/networkxml2xmlin/passthrough-address-crash.xml b/tests/networkxml2xmlin/passthrough-address-crash.xml
new file mode 100644 (file)
index 0000000..a05dbbf
--- /dev/null
@@ -0,0 +1,7 @@
+<network>
+  <name>passthrough_001</name>
+  <uuid>50e92386-8dd1-4a95-8a4b-9a888274eb66</uuid>
+  <forward mode='passthrough'>
+    <address type='pci' domain='0x0000' bus='0x11' slot='0x10' function='0x1'/>
+  </forward>
+</network>
diff --git a/tests/networkxml2xmlout/passthrough-address-crash.xml b/tests/networkxml2xmlout/passthrough-address-crash.xml
new file mode 100644 (file)
index 0000000..a05dbbf
--- /dev/null
@@ -0,0 +1,7 @@
+<network>
+  <name>passthrough_001</name>
+  <uuid>50e92386-8dd1-4a95-8a4b-9a888274eb66</uuid>
+  <forward mode='passthrough'>
+    <address type='pci' domain='0x0000' bus='0x11' slot='0x10' function='0x1'/>
+  </forward>
+</network>
index c6e0f6ff8f22d4f9ad9f706b9c275e9f06b21418..65ac591fb191d6ecdc2983d84b03898cc276d6c7 100644 (file)
@@ -119,6 +119,7 @@ mymain(void)
     DO_TEST_FULL("passthrough-pf", VIR_NETWORK_XML_INACTIVE);
     DO_TEST("hostdev");
     DO_TEST_FULL("hostdev-pf", VIR_NETWORK_XML_INACTIVE);
+    DO_TEST("passthrough-address-crash");
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }