SCC2698Channel has mr[2] and rhr[RX_FIFO_SIZE] (3 bytes), indexed by
mr_idx and rhr_idx during register reads and writes.

vmstate_scc2698_channel restores mr_idx, rhr_idx and rx_pending as raw
uint8_t values. Add a post_load check to ensure mr_idx < ARRAY_SIZE(mr),
rhr_idx < RX_FIFO_SIZE, and rx_pending <= RX_FIFO_SIZE.

Signed-off-by: lbyxiaolizi <[email protected]>
---
 hw/char/ipoctal232.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/hw/char/ipoctal232.c b/hw/char/ipoctal232.c
index b66c20f..c2f4f6c 100644
--- a/hw/char/ipoctal232.c
+++ b/hw/char/ipoctal232.c
@@ -125,10 +125,23 @@ struct IPOctalState {
     uint8_t irq_vector;
 };
 
+static int scc2698_channel_post_load(void *opaque, int version_id)
+{
+    SCC2698Channel *ch = opaque;
+
+    if (ch->mr_idx >= ARRAY_SIZE(ch->mr) ||
+        ch->rhr_idx >= RX_FIFO_SIZE ||
+        ch->rx_pending > RX_FIFO_SIZE) {
+        return -EINVAL;
+    }
+    return 0;
+}
+
 static const VMStateDescription vmstate_scc2698_channel = {
     .name = "scc2698_channel",
     .version_id = 1,
     .minimum_version_id = 1,
+    .post_load = scc2698_channel_post_load,
     .fields = (const VMStateField[]) {
         VMSTATE_BOOL(rx_enabled, SCC2698Channel),
         VMSTATE_UINT8_ARRAY(mr, SCC2698Channel, 2),

Reply via email to