[PATCH] Make really sure we don't access non-existing vCPUs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



MinGW complained that we might be dereferencing a NULL pointer.  While
that's most probably not going to be true (now), the logic certainly
allows for that and we might actually do this a lot in the future with
sparse vcpu mapping.

../../src/conf/domain_conf.c: In function 'virDomainDefGetVcpuPinInfoHelper':
../../src/conf/domain_conf.c:1545:17: error: potential null pointer
dereference [-Werror=null-dereference]
         if (vcpu->cpumask)
              ~~~~^~~~~~~~~

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
I could've pushed this as a build breaker, but I'm not really sure
everyone will like this to be handled this way.  I also did another
fix for this where we don't do int->size_t->int casting all the time,
but it's probably not worth the hassle.  Also I don't know whether
Peter has more stuff for this in his pockets now, so I figured I
rather submit this for review.

 src/conf/domain_conf.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 16e0736e09db..308073897880 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1542,6 +1542,9 @@ virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
         virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(def, i);
         virBitmapPtr bitmap = NULL;

+        if (!vcpu)
+            continue;
+
         if (vcpu->cpumask)
             bitmap = vcpu->cpumask;
         else if (def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO &&
--
2.9.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]