From: Peter Krempa Date: Thu, 21 Aug 2014 09:06:37 +0000 (+0200) Subject: conf: net: Correctly switch how to format address fields X-Git-Tag: v1.2.8-rc1~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4cf1c3fab138462fc9c014aee853fa17f278c5df;p=thirdparty%2Flibvirt.git conf: net: Correctly switch how to format address fields 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 /
element. In case a user would specify an incorrect network type ("passhtrough") with
elements, libvirtd would crash as it would attempt to format an . Use the type of the individual element to format the XML. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1132347 --- diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 756b9dece6..dc25c6ead6 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -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, "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 index 0000000000..a05dbbf837 --- /dev/null +++ b/tests/networkxml2xmlin/passthrough-address-crash.xml @@ -0,0 +1,7 @@ + + passthrough_001 + 50e92386-8dd1-4a95-8a4b-9a888274eb66 + +
+ + diff --git a/tests/networkxml2xmlout/passthrough-address-crash.xml b/tests/networkxml2xmlout/passthrough-address-crash.xml new file mode 100644 index 0000000000..a05dbbf837 --- /dev/null +++ b/tests/networkxml2xmlout/passthrough-address-crash.xml @@ -0,0 +1,7 @@ + + passthrough_001 + 50e92386-8dd1-4a95-8a4b-9a888274eb66 + +
+ + diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index c6e0f6ff8f..65ac591fb1 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -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; }