1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-25 01:34:11 +03:00

Fix segmentation fault when accessing default qemu machine type

This patch fixes a segmentation fault when creating new virtual machines using QEMU.
The segmentation fault is caused by commit f41830680e
and commit cbb6ec42e2.

In virQEMUCapsProbeQMPMachineTypes, when copying machines to qemuCaps, "none" is skipped.
Therefore, the value of i and "qemuCaps->nmachineTypes - 1" do not always match.
However, defIdx value (used to call virQEMUCapsSetDefaultMachine) is set using the value in i
when the array elements are in qemuCaps->nmachineTypes - 1.
So, when libvirt tries to create virtual machines using the default machine type,
qemuCaps->machineTypes[defIdx] is accessed and since the defIdx is NULL, it results in segmentation fault.

Signed-off-by: Yudai Yamagishi <yummy@sfc.wide.ad.jp>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Yudai Yamagish 2013-12-17 17:33:19 +09:00 committed by Jiri Denemark
parent 968fe2c8f8
commit 729530749e

View File

@ -2151,7 +2151,7 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps,
machines[i]->name) < 0)
goto cleanup;
if (machines[i]->isDefault)
defIdx = i;
defIdx = qemuCaps->nmachineTypes - 1;
qemuCaps->machineMaxCpus[qemuCaps->nmachineTypes - 1] =
machines[i]->maxCpus;
}