Skip to contentSkip to conversation

cirrus: keep vga vram pointer within bounds

PATCH New P J P 1 participant 1 message Oct 11, 2017

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH 1/1 cirrus: keep vga vram pointer within bounds

From: Prasad J Pandit <[email protected]>

'dst' pointer could exceed vga vram size when writing to the cirrus memory area; it'd lead to an OOB access issue. Add check to avoid it.

---
 hw/display/cirrus_vga.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Update: fixed coding style error, add space around '<<' operator.

hw/display/cirrus_vga.c +8 -2
index afc290ab91..9f1f856679 100644
@@ -2047,8 +2047,11 @@ static void cirrus_mem_writeb_mode4and5_8bpp(CirrusVGAState * s,
 	}
 	val <<= 1;
 	dst++;
+        if (dst >= s->vga.vram_ptr + s->vga.vram_size) {
+            break;
+        }
     }
-    memory_region_set_dirty(&s->vga.vram, offset, 8);
+    memory_region_set_dirty(&s->vga.vram, offset, x);
 }
 
 static void cirrus_mem_writeb_mode4and5_16bpp(CirrusVGAState * s,
@@ -2071,8 +2074,11 @@ static void cirrus_mem_writeb_mode4and5_16bpp(CirrusVGAState * s,
 	}
 	val <<= 1;
 	dst += 2;
+        if (dst >= s->vga.vram_ptr + s->vga.vram_size) {
+            break;
+        }
     }
-    memory_region_set_dirty(&s->vga.vram, offset, 16);
+    memory_region_set_dirty(&s->vga.vram, offset, x << 1);
 }
 
 /***************************************
Signature · 1 line
2.13.6