The hypervisor may return an index out of range of current vCPUs
defined in the domain which would cause a NULL dereference. Validate
that the vCPU struct with ID fetched from hypervisor exists before
dereferencing it.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
/* TODO: hotplug support */
vcpuInfo = &info[i].vcpuInfo;
- vcpu = virDomainDefGetVcpu(vm->def, vcpuInfo->cpuid);
- vcpupriv = CH_DOMAIN_VCPU_PRIVATE(vcpu);
- vcpupriv->tid = vcpuInfo->tid;
- ncpus++;
+
+ if ((vcpu = virDomainDefGetVcpu(vm->def, vcpuInfo->cpuid))) {
+ vcpupriv = CH_DOMAIN_VCPU_PRIVATE(vcpu);
+ vcpupriv->tid = vcpuInfo->tid;
+ ncpus++;
+ } else {
+ VIR_WARN("vcpu '%d' reported by hypervisor but not found in definition",
+ vcpuInfo->cpuid);
+ }
}
/* TODO: Remove the warning when hotplug is implemented.*/