mvadkert / rpms / qemu

Forked from rpms/qemu 6 years ago
Clone
4d7edd7
From: Prasad J Pandit <pjp@fedoraproject.org>
4d7edd7
Date: Tue, 18 Oct 2016 13:15:17 +0530
4d7edd7
Subject: [PATCH] display: cirrus: check vga bits per pixel(bpp) value
4d7edd7
4d7edd7
In Cirrus CLGD 54xx VGA Emulator, if cirrus graphics mode is VGA,
4d7edd7
'cirrus_get_bpp' returns zero(0), which could lead to a divide
4d7edd7
by zero error in while copying pixel data. The same could occur
4d7edd7
via blit pitch values. Add check to avoid it.
4d7edd7
4d7edd7
Reported-by: Huawei PSIRT <psirt@huawei.com>
4d7edd7
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
4d7edd7
Message-id: 1476776717-24807-1-git-send-email-ppandit@redhat.com
4d7edd7
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
4d7edd7
(cherry picked from commit 4299b90e9ba9ce5ca9024572804ba751aa1a7e70)
4d7edd7
---
4d7edd7
 hw/display/cirrus_vga.c | 14 ++++++++++----
4d7edd7
 1 file changed, 10 insertions(+), 4 deletions(-)
4d7edd7
4d7edd7
diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c
4d7edd7
index 3d712d5..bdb092e 100644
4d7edd7
--- a/hw/display/cirrus_vga.c
4d7edd7
+++ b/hw/display/cirrus_vga.c
4d7edd7
@@ -272,6 +272,9 @@ static void cirrus_update_memory_access(CirrusVGAState *s);
4d7edd7
 static bool blit_region_is_unsafe(struct CirrusVGAState *s,
4d7edd7
                                   int32_t pitch, int32_t addr)
4d7edd7
 {
4d7edd7
+    if (!pitch) {
4d7edd7
+        return true;
4d7edd7
+    }
4d7edd7
     if (pitch < 0) {
4d7edd7
         int64_t min = addr
4d7edd7
             + ((int64_t)s->cirrus_blt_height-1) * pitch;
4d7edd7
@@ -715,7 +718,7 @@ static int cirrus_bitblt_videotovideo_patterncopy(CirrusVGAState * s)
4d7edd7
                                             s->cirrus_addr_mask));
4d7edd7
 }
4d7edd7
 
4d7edd7
-static void cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h)
4d7edd7
+static int cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h)
4d7edd7
 {
4d7edd7
     int sx = 0, sy = 0;
4d7edd7
     int dx = 0, dy = 0;
4d7edd7
@@ -729,6 +732,9 @@ static void cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h)
4d7edd7
         int width, height;
4d7edd7
 
4d7edd7
         depth = s->vga.get_bpp(&s->vga) / 8;
4d7edd7
+        if (!depth) {
4d7edd7
+            return 0;
4d7edd7
+        }
4d7edd7
         s->vga.get_resolution(&s->vga, &width, &height);
4d7edd7
 
4d7edd7
         /* extra x, y */
4d7edd7
@@ -783,6 +789,8 @@ static void cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h)
4d7edd7
     cirrus_invalidate_region(s, s->cirrus_blt_dstaddr,
4d7edd7
 				s->cirrus_blt_dstpitch, s->cirrus_blt_width,
4d7edd7
 				s->cirrus_blt_height);
4d7edd7
+
4d7edd7
+    return 1;
4d7edd7
 }
4d7edd7
 
4d7edd7
 static int cirrus_bitblt_videotovideo_copy(CirrusVGAState * s)
4d7edd7
@@ -790,11 +798,9 @@ static int cirrus_bitblt_videotovideo_copy(CirrusVGAState * s)
4d7edd7
     if (blit_is_unsafe(s))
4d7edd7
         return 0;
4d7edd7
 
4d7edd7
-    cirrus_do_copy(s, s->cirrus_blt_dstaddr - s->vga.start_addr,
4d7edd7
+    return cirrus_do_copy(s, s->cirrus_blt_dstaddr - s->vga.start_addr,
4d7edd7
             s->cirrus_blt_srcaddr - s->vga.start_addr,
4d7edd7
             s->cirrus_blt_width, s->cirrus_blt_height);
4d7edd7
-
4d7edd7
-    return 1;
4d7edd7
 }
4d7edd7
 
4d7edd7
 /***************************************