qemu: command: Validate that memory devices slot ID is in range

slot id, if specified, has to be less than the slots count.
This commit is contained in:
Peter Krempa 2015-04-28 17:15:43 +02:00
parent 406944e476
commit 6705d828fc
3 changed files with 12 additions and 2 deletions

View File

@ -4946,6 +4946,7 @@ qemuBuildMemoryDimmBackendStr(virDomainMemoryDefPtr mem,
char *
qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem,
virDomainDefPtr def,
virQEMUCapsPtr qemuCaps)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
@ -4972,6 +4973,14 @@ qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem,
return NULL;
}
if (mem->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM &&
mem->info.addr.dimm.slot >= def->mem.memory_slots) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("memory device slot '%u' exceeds slots count '%u'"),
mem->info.addr.dimm.slot, def->mem.memory_slots);
return NULL;
}
virBufferAsprintf(&buf, "pc-dimm,node=%d,memdev=mem%s,id=%s",
mem->targetNode, mem->info.alias, mem->info.alias);
@ -8821,7 +8830,7 @@ qemuBuildCommandLine(virConnectPtr conn,
qemuCaps, cfg)))
goto error;
if (!(dimmStr = qemuBuildMemoryDeviceStr(def->mems[i], qemuCaps))) {
if (!(dimmStr = qemuBuildMemoryDeviceStr(def->mems[i], def, qemuCaps))) {
VIR_FREE(backStr);
goto error;
}

View File

@ -175,6 +175,7 @@ int qemuBuildMemoryBackendStr(unsigned long long size,
bool force);
char *qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem,
virDomainDefPtr def,
virQEMUCapsPtr qemuCaps);
/* Legacy, pre device support */

View File

@ -1736,7 +1736,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
if (virAsprintf(&objalias, "mem%s", mem->info.alias) < 0)
goto cleanup;
if (!(devstr = qemuBuildMemoryDeviceStr(mem, priv->qemuCaps)))
if (!(devstr = qemuBuildMemoryDeviceStr(mem, vm->def, priv->qemuCaps)))
goto cleanup;
qemuDomainMemoryDeviceAlignSize(mem);