File 67b973b5-qemuDomainDefPostParse-no-machine.patch of Package libvirt.29527

commit 67b973b510ad68da06e8eb744d97b3e1df5fbcbe
Author: Michal Prívozník <mprivozn@redhat.com>
Date:   Thu Apr 16 14:18:28 2020 +0200

    qemuDomainDefPostParse: Fail if unable to fill machine type
    
    Previously, we used virCapabilitiesDomainDataLookup() to fill
    machine type in post parse callback if none was provided in the
    domain XML. If machine type couldn't be filled in an error was
    reported. After 4a4132b4625 we've changed it to
    virQEMUCapsGetPreferredMachine() which returns NULL, but we no
    longer report an error and proceed with the post parse callbacks
    processing. This may lead to a crash because the code later on
    assumes def->os.machine is not NULL.
    
    Fixes: 4a4132b4625
    
    Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
    Reviewed-by: Pavel Mores <pmores@redhat.com>

Index: libvirt-6.0.0/src/qemu/qemu_domain.c
===================================================================
--- libvirt-6.0.0.orig/src/qemu/qemu_domain.c
+++ libvirt-6.0.0/src/qemu/qemu_domain.c
@@ -4908,6 +4908,14 @@ qemuDomainDefPostParse(virDomainDefPtr d
     if (!def->os.machine) {
         const char *machine = virQEMUCapsGetPreferredMachine(qemuCaps,
                                                              def->virtType);
+        if (!machine) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("could not get preferred machine for %s type=%s"),
+                           def->emulator,
+                           virDomainVirtTypeToString(def->virtType));
+            return -1;
+        }
+
         def->os.machine = g_strdup(machine);
     }
 
openSUSE Build Service is sponsored by