For objects with a subtype 'type' attribute, when the _new_from_xml function was called, the 'type' attribute was forcefully set to the right value rather than checking that the passed-in value matches the type of the subclass we are trying to instantiate. This commit changes this, and returns NULL when the value of the 'type' attribute of the passed-in XML document does not match the expected type. --- libvirt-gconfig/libvirt-gconfig-domain-address-pci.c | 5 ++++- libvirt-gconfig/libvirt-gconfig-domain-address-usb.c | 5 ++++- libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.c | 5 ++++- libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.c | 5 ++++- libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c | 5 ++++- libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.c | 5 +++-- libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c | 5 +++-- libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c | 5 +++-- libvirt-gconfig/libvirt-gconfig-domain-interface-bridge.c | 5 +++-- libvirt-gconfig/libvirt-gconfig-domain-interface-network.c | 5 +++-- libvirt-gconfig/libvirt-gconfig-domain-interface-user.c | 5 +++-- libvirt-gconfig/libvirt-gconfig-domain-timer-pit.c | 5 ++++- libvirt-gconfig/libvirt-gconfig-domain-timer-rtc.c | 5 ++++- 13 files changed, 46 insertions(+), 19 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c index 48e3872..16fe256 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c @@ -67,7 +67,10 @@ GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new_from_xml(const gc object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI, "address", NULL, xml, error); - gvir_config_object_set_attribute(object, "type", "pci", NULL); + if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "pci") != 0) { + g_object_unref(G_OBJECT(object)); + return NULL; + } return GVIR_CONFIG_DOMAIN_ADDRESS_PCI(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-usb.c b/libvirt-gconfig/libvirt-gconfig-domain-address-usb.c index 3da5811..fdddcfb 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-address-usb.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-usb.c @@ -67,7 +67,10 @@ GVirConfigDomainAddressUsb *gvir_config_domain_address_usb_new_from_xml(const gc object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_USB, "address", NULL, xml, error); - gvir_config_object_set_attribute(object, "type", "usb", NULL); + if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "usb") != 0) { + g_object_unref(G_OBJECT(object)); + return NULL; + } return GVIR_CONFIG_DOMAIN_ADDRESS_USB(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.c b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.c index 201e123..12e6f18 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.c @@ -75,7 +75,10 @@ GVirConfigDomainChardevSourcePty *gvir_config_domain_chardev_source_pty_new_from */ object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_PTY, "dummy", NULL, xml, error); - gvir_config_object_set_attribute(object, "type", "pty", NULL); + if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "pty") != 0) { + g_object_unref(G_OBJECT(object)); + return NULL; + } return GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.c b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.c index 22eabf5..3590e55 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.c @@ -75,6 +75,9 @@ GVirConfigDomainChardevSourceSpiceVmc *gvir_config_domain_chardev_source_spicevm */ object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_SPICE_VMC, "dummy", NULL, xml, error); - gvir_config_object_set_attribute(object, "type", "spicevmc", NULL); + if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "spicevmc") != 0) { + g_object_unref(G_OBJECT(object)); + return NULL; + } return GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_SPICE_VMC(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c b/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c index 1fd248c..f4d3901 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c @@ -167,7 +167,10 @@ GVirConfigDomainControllerUsb *gvir_config_domain_controller_usb_new_from_xml(co object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER_USB, "controller", NULL, xml, error); - gvir_config_object_set_attribute(object, "type", "usb", NULL); + if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "usb") != 0) { + g_object_unref(G_OBJECT(object)); + return NULL; + } return GVIR_CONFIG_DOMAIN_CONTROLLER_USB(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.c b/libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.c index 7871ae5..8b22ad0 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.c @@ -68,9 +68,10 @@ gvir_config_domain_graphics_sdl_new_from_xml(const gchar *xml, object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_SDL, "graphics", NULL, xml, error); - if (object == NULL) + if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "sdl") != 0) { + g_object_unref(G_OBJECT(object)); return NULL; - gvir_config_object_set_attribute(object, "type", "sdl", NULL); + } return GVIR_CONFIG_DOMAIN_GRAPHICS_SDL(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c index e60a778..61d3f5b 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c @@ -68,9 +68,10 @@ gvir_config_domain_graphics_spice_new_from_xml(const gchar *xml, object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_SPICE, "graphics", NULL, xml, error); - if (object == NULL) + if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "spice") != 0) { + g_object_unref(G_OBJECT(object)); return NULL; - gvir_config_object_set_attribute(object, "type", "spice", NULL); + } return GVIR_CONFIG_DOMAIN_GRAPHICS_SPICE(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c b/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c index d9d1303..f2fc9d5 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c @@ -68,9 +68,10 @@ gvir_config_domain_graphics_vnc_new_from_xml(const gchar *xml, object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_VNC, "graphics", NULL, xml, error); - if (object == NULL) + if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "vnc") != 0) { + g_object_unref(G_OBJECT(object)); return NULL; - gvir_config_object_set_attribute(object, "type", "vnc", NULL); + } return GVIR_CONFIG_DOMAIN_GRAPHICS_VNC(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-domain-interface-bridge.c b/libvirt-gconfig/libvirt-gconfig-domain-interface-bridge.c index ea5eafa..09a7efc 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-interface-bridge.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-interface-bridge.c @@ -70,9 +70,10 @@ GVirConfigDomainInterfaceBridge *gvir_config_domain_interface_bridge_new_from_xm object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_INTERFACE_BRIDGE, "interface", NULL, xml, error); - if (object == NULL) + if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "bridge") != 0) { + g_object_unref(G_OBJECT(object)); return NULL; - gvir_config_object_set_attribute(object, "type", "bridge", NULL); + } return GVIR_CONFIG_DOMAIN_INTERFACE_BRIDGE(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-domain-interface-network.c b/libvirt-gconfig/libvirt-gconfig-domain-interface-network.c index 1a7bfad..ce39234 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-interface-network.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-interface-network.c @@ -69,9 +69,10 @@ GVirConfigDomainInterfaceNetwork *gvir_config_domain_interface_network_new_from_ object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_INTERFACE_NETWORK, "interface", NULL, xml, error); - if (object == NULL) + if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "network") != 0) { + g_object_unref(G_OBJECT(object)); return NULL; - gvir_config_object_set_attribute(object, "type", "network", NULL); + } return GVIR_CONFIG_DOMAIN_INTERFACE_NETWORK(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-domain-interface-user.c b/libvirt-gconfig/libvirt-gconfig-domain-interface-user.c index a455a73..4ede31f 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-interface-user.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-interface-user.c @@ -69,8 +69,9 @@ GVirConfigDomainInterfaceUser *gvir_config_domain_interface_user_new_from_xml(co object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_INTERFACE_USER, "interface", NULL, xml, error); - if (object == NULL) + if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "user") != 0) { + g_object_unref(G_OBJECT(object)); return NULL; - gvir_config_object_set_attribute(object, "type", "user", NULL); + } return GVIR_CONFIG_DOMAIN_INTERFACE_USER(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-domain-timer-pit.c b/libvirt-gconfig/libvirt-gconfig-domain-timer-pit.c index d75cd30..16f7e03 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-timer-pit.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-timer-pit.c @@ -67,6 +67,9 @@ GVirConfigDomainTimerPit *gvir_config_domain_timer_pit_new_from_xml(const gchar object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_TIMER_PIT, "timer", NULL, xml, error); - gvir_config_object_set_attribute(object, "name", "pit", NULL); + if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "pit") != 0) { + g_object_unref(G_OBJECT(object)); + return NULL; + } return GVIR_CONFIG_DOMAIN_TIMER_PIT(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-domain-timer-rtc.c b/libvirt-gconfig/libvirt-gconfig-domain-timer-rtc.c index b99c1e3..19783df 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-timer-rtc.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-timer-rtc.c @@ -67,6 +67,9 @@ GVirConfigDomainTimerRtc *gvir_config_domain_timer_rtc_new_from_xml(const gchar object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_TIMER_RTC, "timer", NULL, xml, error); - gvir_config_object_set_attribute(object, "name", "rtc", NULL); + if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "rtc") != 0) { + g_object_unref(G_OBJECT(object)); + return NULL; + } return GVIR_CONFIG_DOMAIN_TIMER_RTC(object); } -- 1.7.10.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list