summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2011-06-03 13:53:26 -0600
committerEric Blake <eblake@redhat.com>2011-06-08 05:28:20 -0600
commite360d2ef588b4f57a4c7e74aa1c9177f15445a92 (patch)
tree7ca1f1b8adbf033ea7a43f7e093a73b0864db2e8
parentd4bd086156663a972fcafc3b0aca857dddae1194 (diff)
downloadlibvirt-python-split-e360d2ef588b4f57a4c7e74aa1c9177f15445a92.tar.gz
libvirt-python-split-e360d2ef588b4f57a4c7e74aa1c9177f15445a92.tar.xz
libvirt-python-split-e360d2ef588b4f57a4c7e74aa1c9177f15445a92.zip
python: avoid unlikely sign extension bug
Detected by Coverity. cpumap was allocated with a value of (unsigned short)*(int), which is an int computation, and then promotes to size_t. On a 64-bit platform, this fails if bit 32 of the product is set (because of sign extension giving a HUGE value to malloc), even though a naive programmer would assume that since the first value is unsigned, the product is also unsigned and at most 4GB would be allocated. Won't bite in practice (the product should never be that large), but worth using the right types to begin with, so that we are now computing (unsigned short)*(size_t). * python/libvirt-override.c (libvirt_virDomainGetVcpus): Use correct type.
-rw-r--r--libvirt-override.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/libvirt-override.c b/libvirt-override.c
index 763df00..974decb 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -414,7 +414,7 @@ libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
virDomainInfo dominfo;
virVcpuInfoPtr cpuinfo = NULL;
unsigned char *cpumap = NULL;
- int cpumaplen, i;
+ size_t cpumaplen, i;
int i_retval;
if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetVcpus",