@@ -338,7 +338,7 @@ static void fw_cfg_dma_transfer(FWCfgState *s)
while (dma.length > 0 && !(dma.control & FW_CFG_DMA_CTL_ERROR)) {
if (s->cur_entry == FW_CFG_INVALID || !e->data ||
s->cur_offset >= e->len) {
- len = dma.length;
+ len = dma.length > INT32_MAX ? INT32_MAX : dma.length;
/* If the access is not a read access, it will be a skip access,
* tested before.
@@ -358,6 +358,8 @@ static void fw_cfg_dma_transfer(FWCfgState *s)
len = (e->len - s->cur_offset);
}
+ len = len > INT32_MAX ? INT32_MAX : len;
+
/* If the access is not a read access, it will be a skip access,
* tested before.
*/