[PATCH] Avoid integer wrap on remotePortMax in QEMU driver

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

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

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 | 4 ++--
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 680e8fb..b21392e 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -233,10 +233,6 @@ int qemuLoadDriverConfig(virQEMUDriverPtr driver,
                        filename, QEMU_REMOTE_PORT_MAX);
         goto cleanup;
     }
-    /* increasing the value by 1 makes all the loops going through
-    the bitmap (i = remotePortMin; i < remotePortMax; i++), work as
-    expected. */
-    driver->remotePortMax++;
 
     if (driver->remotePortMin > driver->remotePortMax) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c
index 033aee4..5d07dd0 100644
--- a/src/util/virportallocator.c
+++ b/src/util/virportallocator.c
@@ -84,7 +84,7 @@ virPortAllocatorPtr virPortAllocatorNew(unsigned short start,
     pa->start = start;
     pa->end = end;
 
-    if (!(pa->bitmap = virBitmapNew(end-start))) {
+    if (!(pa->bitmap = virBitmapNew((end-start)+1))) {
         virReportOOMError();
         virObjectUnref(pa);
         return NULL;
@@ -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;
         struct sockaddr_in addr;
         bool used = false;
-- 
1.8.0.2

--
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]