[libvirt] [PATCH v2] Avoid integer wrap on remotePortMax in QEMU driver
Eric Blake
eblake at redhat.com
Thu Jan 17 19:06:24 UTC 2013
On 01/17/2013 06:00 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange at redhat.com>
>
> The QEMU driver default max port is 65535, but it then increments
> this by 1 to 65536. This maps to 0 in an unsigned short :-( This
> was apparently done so that for() loops could use "< max" instead
> of "<= max". Remove this insanity and just make the loop do the
> right thing.
> ---
> src/qemu/qemu_conf.c | 4 ----
> src/util/virportallocator.c | 6 +++---
> tests/virportallocatortest.c | 2 +-
> 3 files changed, 4 insertions(+), 8 deletions(-)
>
> @@ -103,7 +103,7 @@ int virPortAllocatorAcquire(virPortAllocatorPtr pa,
> *port = 0;
> virObjectLock(pa);
>
> - for (i = pa->start ; i < pa->end && !*port; i++) {
> + for (i = pa->start ; i <= pa->end && !*port; i++) {
> int reuse = 1;
This loop is still broken, unless you change the type of 'i' to be wider
than unsigned short.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20130117/3cc7fa7c/attachment-0001.sig>
More information about the libvir-list
mailing list