]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Fix crash in qemucapsprobe
authorJiri Denemark <jdenemar@redhat.com>
Tue, 27 Sep 2016 11:39:51 +0000 (13:39 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 27 Sep 2016 17:24:12 +0000 (19:24 +0200)
The qemucapsprobe helper calls virQEMUCapsNewForBinaryInternal with
caps == NULL, causing the following crash:

    Program received signal SIGSEGV, Segmentation fault.
    #0  0x00007ffff788775f in virQEMUCapsInitHostCPUModel
        (qemuCaps=qemuCaps@entry=0x649680, host=host@entry=0x10) at
        src/qemu/qemu_capabilities.c:2969
    #1  0x00007ffff7889dbf in virQEMUCapsNewForBinaryInternal
        (caps=caps@entry=0x0, binary=<optimized out>,
        libDir=libDir@entry=0x4033f6 "/tmp", cacheDir=cacheDir@entry=0x0,
        runUid=runUid@entry=4294967295, runGid=runGid@entry=4294967295,
        qmpOnly=true) at src/qemu/qemu_capabilities.c:4039
    #2  0x0000000000401702 in main (argc=2, argv=0x7fffffffd968) at
        tests/qemucapsprobe.c:73

Caused by v2.2.0-182-g68c7011.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
src/qemu/qemu_capabilities.c
src/qemu/qemu_capspriv.h
tests/qemuxml2argvtest.c

index 4d859c4dacacda4c510844f9c0bed99f4b67a321..cc8ec5857111e4ff40eacd179caa595fa094efeb 100644 (file)
@@ -2962,14 +2962,17 @@ virQEMUCapsCPUFilterFeatures(const char *name,
 
 void
 virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
-                            virCapsHostPtr host)
+                            virCapsPtr caps)
 {
     virCPUDefPtr cpu = NULL;
 
-    if (!virQEMUCapsGuestIsNative(host->arch, qemuCaps->arch))
+    if (!caps)
+        return;
+
+    if (!virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch))
         goto error;
 
-    if (host->cpu && host->cpu->model) {
+    if (caps->host.cpu && caps->host.cpu->model) {
         if (VIR_ALLOC(cpu) < 0)
             goto error;
 
@@ -2978,7 +2981,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
         cpu->mode = VIR_CPU_MODE_CUSTOM;
         cpu->match = VIR_CPU_MATCH_EXACT;
 
-        if (virCPUDefCopyModelFilter(cpu, host->cpu, true,
+        if (virCPUDefCopyModelFilter(cpu, caps->host.cpu, true,
                                      virQEMUCapsCPUFilterFeatures, NULL) < 0)
             goto error;
     }
@@ -3248,7 +3251,7 @@ virQEMUCapsLoadCache(virCapsPtr caps,
     }
     VIR_FREE(nodes);
 
-    virQEMUCapsInitHostCPUModel(qemuCaps, &caps->host);
+    virQEMUCapsInitHostCPUModel(qemuCaps, caps);
 
     ret = 0;
  cleanup:
@@ -4036,7 +4039,7 @@ virQEMUCapsNewForBinaryInternal(virCapsPtr caps,
             virQEMUCapsRememberCached(qemuCaps, cacheDir) < 0)
             goto error;
 
-        virQEMUCapsInitHostCPUModel(qemuCaps, &caps->host);
+        virQEMUCapsInitHostCPUModel(qemuCaps, caps);
     }
 
  cleanup:
index 22c5a8ae5b75946b985c6bc646976d51a0377365..fab2c2acd3501b0b5edc5be320e9ad890a32aa13 100644 (file)
@@ -64,5 +64,5 @@ virQEMUCapsSetArch(virQEMUCapsPtr qemuCaps,
 
 void
 virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
-                            virCapsHostPtr host);
+                            virCapsPtr caps);
 #endif
index 0af71a1dbce502920851c7472254a92c2f10c316..4b9ecb82f8bc7d081a41a2e50f53497ac334afb5 100644 (file)
@@ -357,7 +357,7 @@ testUpdateQEMUCaps(const struct testInfo *info,
     if (testAddCPUModels(info->qemuCaps, info->skipLegacyCPUs) < 0)
         goto cleanup;
 
-    virQEMUCapsInitHostCPUModel(info->qemuCaps, &caps->host);
+    virQEMUCapsInitHostCPUModel(info->qemuCaps, caps);
 
     virQEMUCapsFilterByMachineType(info->qemuCaps, vm->def->os.machine);