From: Peter Krempa <pkre...@redhat.com> 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 <pkre...@redhat.com> --- src/ch/ch_domain.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ch/ch_domain.c b/src/ch/ch_domain.c index 7231fdc49f..85bd99e1e9 100644 --- a/src/ch/ch_domain.c +++ b/src/ch/ch_domain.c @@ -276,10 +276,15 @@ virCHDomainRefreshThreadInfo(virDomainObj *vm) /* 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.*/ -- 2.50.1