qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/scsi/esp: fix assertion error in fifo8_push
@ 2025-05-27 13:12 Zheng Huang
  2025-05-27 13:59 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 7+ messages in thread
From: Zheng Huang @ 2025-05-27 13:12 UTC (permalink / raw)
  To: qemu-devel

This patch add validation checks on FIFO structures in esp_post_load() to
avoid assertion error `assert(fifo->num < fifo->capacity);` in fifo8_push(),
which can occur if the inbound migration stream is malformed. By performing 
these checks during post-load, we can catch and handle such issues earlier, 
avoiding crashes due to corrupted state.

Signed-off-by: Zheng Huang <hz1624917200@gmail.com>
---
 hw/scsi/esp.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
index ac841dc32e..ba77017087 100644
--- a/hw/scsi/esp.c
+++ b/hw/scsi/esp.c
@@ -1350,11 +1350,17 @@ static int esp_post_load(void *opaque, int version_id)
         /* Migrate ti_buf to fifo */
         len = s->mig_ti_wptr - s->mig_ti_rptr;
         for (i = 0; i < len; i++) {
+            if (&s->fifo.num >= &s->fifo.capacity) {
+                return -1;
+            }
             fifo8_push(&s->fifo, s->mig_ti_buf[i]);
         }
 
         /* Migrate cmdbuf to cmdfifo */
         for (i = 0; i < s->mig_cmdlen; i++) {
+            if (&s->cmdfifo.num >= &s->cmdfifo.capacity) {
+                return -1;
+            }
             fifo8_push(&s->cmdfifo, s->mig_cmdbuf[i]);
         }
     }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-05-29  9:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-27 13:12 [PATCH] hw/scsi/esp: fix assertion error in fifo8_push Zheng Huang
2025-05-27 13:59 ` Philippe Mathieu-Daudé
2025-05-27 19:40   ` Mark Cave-Ayland
2025-05-28  5:51     ` Zheng Huang
2025-05-28 13:07       ` Fabiano Rosas
2025-05-29  9:38         ` Zheng Huang
2025-05-28  5:54     ` Zheng Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).