From: GuoHan Zhao <[email protected]>
Fix a null pointer dereference issue.
The code dereferences s->current before checking if it is NULL. Move the
null check before the dereference to prevent potential crashes.
This issue could occur if s->current is NULL when the function reaches
the "Host adapter (re)connected" path, though this should not normally
happen during correct operation.
Fixes: 9ce93b74cdc0 ("ncr710: Add driver for the NCR 53c710 SCSI chip")
Signed-off-by: GuoHan Zhao <[email protected]>
---
hw/scsi/ncr53c710.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/hw/scsi/ncr53c710.c b/hw/scsi/ncr53c710.c
index ade951b1d107..e479a212bc54 100644
--- a/hw/scsi/ncr53c710.c
+++ b/hw/scsi/ncr53c710.c
@@ -831,14 +831,14 @@ void ncr710_transfer_data(SCSIRequest *req, uint32_t len)
}
}
- /* Host adapter (re)connected */
- s->current->dma_len = len;
- s->command_complete = NCR710_CMD_DATA_READY;
-
if (!s->current) {
return;
}
+ /* Host adapter (re)connected */
+ s->current->dma_len = len;
+ s->command_complete = NCR710_CMD_DATA_READY;
+
if (s->waiting) {
s->scntl1 |= NCR710_SCNTL1_CON;
s->istat |= NCR710_ISTAT_CON;
--
2.43.0