]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Fix crash on failed VM startup
authorCole Robinson <crobinso@redhat.com>
Tue, 1 Jun 2010 19:10:19 +0000 (15:10 -0400)
committerCole Robinson <crobinso@redhat.com>
Fri, 18 Jun 2010 14:14:34 +0000 (10:14 -0400)
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@redhat.com>
src/qemu/qemu_driver.c
src/util/bitmap.c

index c7923bc6947cf5e85dcf7fdcfb7f4ff1477f1ffe..167e077a1db7fc54d7c775cd4c78bb74d00f6a2f 100644 (file)
@@ -3773,7 +3773,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) {
index 44edb4934ed0f7a5a39991af1fa177129482770a..0f7e82e0ec0490e2a6a1603b220206276924404d 100644 (file)
@@ -119,7 +119,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));