qxl: add sanity check
authorGerd Hoffmann <kraxel@redhat.com>
Wed, 19 Feb 2014 10:40:17 +0000 (11:40 +0100)
committerGerd Hoffmann <kraxel@redhat.com>
Mon, 24 Feb 2014 12:00:52 +0000 (13:00 +0100)
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
hw/display/qxl.c

index 1471cc093bd5798a5d7a3b18009514e98daed4e8..2a559ebcc9667cf8cf68ebb076aefb84120775eb 100644 (file)
@@ -1429,7 +1429,7 @@ static int qxl_destroy_primary(PCIQXLDevice *d, qxl_async_io async)
     return 1;
 }
 
-static void qxl_set_mode(PCIQXLDevice *d, int modenr, int loadvm)
+static void qxl_set_mode(PCIQXLDevice *d, unsigned int modenr, int loadvm)
 {
     pcibus_t start = d->pci.io_regions[QXL_RAM_RANGE_INDEX].addr;
     pcibus_t end   = d->pci.io_regions[QXL_RAM_RANGE_INDEX].size + start;
@@ -1439,6 +1439,12 @@ static void qxl_set_mode(PCIQXLDevice *d, int modenr, int loadvm)
         .mem_start = start,
         .mem_end = end
     };
+
+    if (modenr >= d->modes->n_modes) {
+        qxl_set_guest_bug(d, "mode number out of range");
+        return;
+    }
+
     QXLSurfaceCreate surface = {
         .width      = mode->x_res,
         .height     = mode->y_res,