Skip to content

Commit 14d0ddf

Browse files
mcaylandvivier
authored andcommitted
macfb: fix overflow of color_palette array
The palette_current index counter has a maximum size of 256 * 3 to cover a full color palette of 256 RGB entries. Linux assumes that the palette_current index wraps back around to zero after writing 256 RGB entries so ensure that palette_current is reset at this point to prevent data corruption within MacfbState. Signed-off-by: Mark Cave-Ayland <[email protected]> Reviewed-by: Laurent Vivier <[email protected]> Message-Id: <[email protected]> Signed-off-by: Laurent Vivier <[email protected]>
1 parent 906c232 commit 14d0ddf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

hw/display/macfb.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ static void macfb_ctrl_write(void *opaque,
303303
s->palette_current = 0;
304304
break;
305305
case DAFB_LUT:
306-
s->color_palette[s->palette_current++] = val;
306+
s->color_palette[s->palette_current] = val;
307+
s->palette_current = (s->palette_current + 1) %
308+
ARRAY_SIZE(s->color_palette);
307309
if (s->palette_current % 3) {
308310
macfb_invalidate_display(s);
309311
}

0 commit comments

Comments
 (0)