[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH for 3.1 3/4] virtio-scsi/migration: Allow load_reque
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH for 3.1 3/4] virtio-scsi/migration: Allow load_request to fail |
Date: |
Mon, 16 Jul 2018 18:37:42 +0100 |
From: "Dr. David Alan Gilbert" <address@hidden>
Rather than asserting, check values and return NULL
on failure.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
hw/scsi/virtio-scsi.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 6301af76ad..3441bfe6d7 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -204,7 +204,11 @@ static void *virtio_scsi_load_request(QEMUFile *f,
SCSIRequest *sreq)
uint32_t n;
qemu_get_be32s(f, &n);
- assert(n < vs->conf.num_queues);
+ if (n >= vs->conf.num_queues) {
+ error_report("%s: Bad queue number (%d vs %d)",
+ __func__, n, vs->conf.num_queues);
+ return NULL;
+ }
req = qemu_get_virtqueue_element(vdev, f,
sizeof(VirtIOSCSIReq) + vs->cdb_size);
if (!req) {
@@ -216,13 +220,18 @@ static void *virtio_scsi_load_request(QEMUFile *f,
SCSIRequest *sreq)
if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size,
sizeof(VirtIOSCSICmdResp) + vs->sense_size) < 0)
{
error_report("invalid SCSI request migration data");
- exit(1);
+ return NULL;
}
scsi_req_ref(sreq);
req->sreq = sreq;
if (req->sreq->cmd.mode != SCSI_XFER_NONE) {
- assert(req->sreq->cmd.mode == req->mode);
+ if (req->sreq->cmd.mode != req->mode) {
+ error_report("%s: Bad mode (%d vs %d)",
+ __func__, req->sreq->cmd.mode, req->mode);
+ scsi_req_unref(sreq);
+ return NULL;
+ }
}
return req;
}
--
2.17.1