Since the returned structure uses "unsigned long" for memory sizes add a few overflow checks to notify the user in case we are not able to represent given values. --- src/qemu/qemu_driver.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1ff4237..92da08d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2612,9 +2612,12 @@ static int qemuDomainSendKey(virDomainPtr domain, return ret; } -static int qemuDomainGetInfo(virDomainPtr dom, - virDomainInfoPtr info) + +static int +qemuDomainGetInfo(virDomainPtr dom, + virDomainInfoPtr info) { + unsigned long long maxmem; virQEMUDriverPtr driver = dom->conn->privateData; virDomainObjPtr vm; int ret = -1; @@ -2625,30 +2628,34 @@ static int qemuDomainGetInfo(virDomainPtr dom, if (virDomainGetInfoEnsureACL(dom->conn, vm->def) < 0) goto cleanup; + if (qemuDomainUpdateCurrentMemorySize(driver, vm) < 0) + goto cleanup; + + memset(info, 0, sizeof(*info)); + info->state = virDomainObjGetState(vm, NULL); - if (!virDomainObjIsActive(vm)) { - info->cpuTime = 0; - } else { - if (qemuGetProcessInfo(&(info->cpuTime), NULL, NULL, vm->pid, 0) < 0) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("cannot read cputime for domain")); - goto cleanup; - } + maxmem = virDomainDefGetMemoryActual(vm->def); + if (VIR_ASSIGN_IS_OVERFLOW(info->maxMem, maxmem)) { + virReportError(VIR_ERR_OVERFLOW, "%s", + _("Initial memory size too large")); + goto cleanup; } - info->maxMem = virDomainDefGetMemoryActual(vm->def); - if (virDomainObjIsActive(vm)) { - if (qemuDomainUpdateCurrentMemorySize(driver, vm) < 0) + if (VIR_ASSIGN_IS_OVERFLOW(info->memory, vm->def->mem.cur_balloon)) { + virReportError(VIR_ERR_OVERFLOW, "%s", + _("Current memory size too large")); goto cleanup; + } - info->memory = vm->def->mem.cur_balloon; - } else { - info->memory = 0; + if (qemuGetProcessInfo(&(info->cpuTime), NULL, NULL, vm->pid, 0) < 0) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("cannot read cputime for domain")); + goto cleanup; + } } - info->nrVirtCpu = vm->def->vcpus; ret = 0; cleanup: -- 2.4.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list