[libvirt] [PATCH] qemu: Fix crash on failed VM startup

Cole Robinson crobinso at redhat.com
Tue Jun 1 19:10:19 UTC 2010


If VM startup fails early enough (can't find a referenced USB device),
libvirtd will crash trying to clear the VNC port bit, since port = 0,
which overflows us out of the bitmap bounds.

Fix this by being more defensive in the bitmap operations, and only
clearing a previously set VNC port.

Signed-off-by: Cole Robinson <crobinso at redhat.com>
---
 src/qemu/qemu_driver.c |    2 +-
 src/util/bitmap.c      |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c8cd50a..f5a1310 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3741,7 +3741,7 @@ retry:
     if ((vm->def->ngraphics == 1) &&
         vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
         vm->def->graphics[0]->data.vnc.autoport &&
-        vm->def->graphics[0]->data.vnc.port != -1) {
+        vm->def->graphics[0]->data.vnc.port >= QEMU_VNC_PORT_MIN) {
         if (virBitmapClearBit(driver->reservedVNCPorts,
                               vm->def->graphics[0]->data.vnc.port - \
                               QEMU_VNC_PORT_MIN) < 0) {
diff --git a/src/util/bitmap.c b/src/util/bitmap.c
index 69094a5..98e65f8 100644
--- a/src/util/bitmap.c
+++ b/src/util/bitmap.c
@@ -118,7 +118,7 @@ int virBitmapSetBit(virBitmapPtr bitmap, size_t b)
  */
 int virBitmapClearBit(virBitmapPtr bitmap, size_t b)
 {
-    if (b > bitmap->size - 1)
+    if (bitmap->size != 0 && b > bitmap->size - 1)
         return -1;
 
     bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] &= ~(1 << VIR_BITMAP_BIT_OFFSET(b));
-- 
1.6.6.1




More information about the libvir-list mailing list