1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

Fix crash formatting virtio console

qemuBuildVirtioSerialPortDevStr was mistakenly accessing the
target.name field in the virDomainChrDef object for chardevs
belonging to a console. Those chardevs only have port set,
and if there's > 1 console, the > 1port number results in
trying to access a target.name with address 0x1

* src/qemu/qemu_command.c: Fix target.name handling and
  make code more robust wrt error reporting

* src/qemu/qemu_command.c: Conditionally access target.name
This commit is contained in:
Daniel P. Berrange 2011-10-19 11:45:10 +01:00
parent 0873b688c6
commit 5990d92192

View File

@ -2852,13 +2852,24 @@ qemuBuildVirtioSerialPortDevStr(virDomainChrDefPtr dev,
virBitmapPtr qemuCaps) virBitmapPtr qemuCaps)
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
if (dev->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE) switch (dev->deviceType) {
case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
virBufferAddLit(&buf, "virtconsole"); virBufferAddLit(&buf, "virtconsole");
else if (qemuCapsGet(qemuCaps, QEMU_CAPS_DEVICE_SPICEVMC) && break;
dev->source.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL:
/* Legacy syntax '-device spicevmc' */
if (dev->source.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC &&
qemuCapsGet(qemuCaps, QEMU_CAPS_DEVICE_SPICEVMC)) {
virBufferAddLit(&buf, "spicevmc"); virBufferAddLit(&buf, "spicevmc");
else } else {
virBufferAddLit(&buf, "virtserialport"); virBufferAddLit(&buf, "virtserialport");
}
break;
default:
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Cannot use virtio serial for parallel/serial devices"));
return NULL;
}
if (dev->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) { if (dev->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
/* Check it's a virtio-serial address */ /* Check it's a virtio-serial address */
@ -2879,7 +2890,8 @@ qemuBuildVirtioSerialPortDevStr(virDomainChrDefPtr dev,
dev->info.addr.vioserial.port); dev->info.addr.vioserial.port);
} }
if (dev->source.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC && if (dev->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
dev->source.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC &&
dev->target.name && dev->target.name &&
STRNEQ(dev->target.name, "com.redhat.spice.0")) { STRNEQ(dev->target.name, "com.redhat.spice.0")) {
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@ -2887,15 +2899,18 @@ qemuBuildVirtioSerialPortDevStr(virDomainChrDefPtr dev,
dev->target.name); dev->target.name);
goto error; goto error;
} }
if (qemuCapsGet(qemuCaps, QEMU_CAPS_DEVICE_SPICEVMC) &&
dev->source.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) { if (!(dev->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
virBufferAsprintf(&buf, ",id=%s", dev->info.alias); dev->source.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC &&
} else { qemuCapsGet(qemuCaps, QEMU_CAPS_DEVICE_SPICEVMC))) {
virBufferAsprintf(&buf, ",chardev=char%s,id=%s", virBufferAsprintf(&buf, ",chardev=char%s,id=%s",
dev->info.alias, dev->info.alias); dev->info.alias, dev->info.alias);
if (dev->target.name) { if (dev->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
dev->target.name) {
virBufferAsprintf(&buf, ",name=%s", dev->target.name); virBufferAsprintf(&buf, ",name=%s", dev->target.name);
} }
} else {
virBufferAsprintf(&buf, ",id=%s", dev->info.alias);
} }
if (virBufferError(&buf)) { if (virBufferError(&buf)) {
virReportOOMError(); virReportOOMError();