]> xenbits.xensource.com Git - libvirt.git/commit
python: avoid unlikely sign extension bug
authorEric Blake <eblake@redhat.com>
Fri, 3 Jun 2011 19:53:26 +0000 (13:53 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 8 Jun 2011 11:28:20 +0000 (05:28 -0600)
commitf73198df3b9ee2e3cca20e7aa7e75fe191dac7f6
tree81bbe4023bc2d17b565510b44520c1c167fd836a
parentf876c30cfe09cb86bd4bdb019c89d2b9d9e3217f
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.
python/libvirt-override.c