[PATCH v3 5/7] mptsas: do not crash QEMU on migration errors
Laurent Vivier <[email protected]>
| Newsgroups | gmane.comp.emulators.qemu.block,gmane.comp.emulators.qemu |
|---|---|
| Message-ID | <[email protected]> |
From: "Michael S. Tsirkin" <[email protected]> Currently mptsas asserts on invalid sg list count in the migration stream. Fail migration gracefully instead. Signed-off-by: Michael S. Tsirkin <[email protected]> [lvivier: use errp rather than qemu_file_set_error() to report error] Signed-off-by: Laurent Vivier <[email protected]> --- Notes: v2: new patch from Michael S. Tsirkin https://lore.kernel.org/qemu-devel/258d84f5af807e0103bf6f59165dd7450918e58c.1784898250.git.mst@redhat.com/ Modified to use errp parameter with error_setg() instead of qemu_file_set_error() to report error hw/scsi/mptsas.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/scsi/mptsas.c b/hw/scsi/mptsas.c index 45638af0afc3..34ceb6b5d25e 100644 --- a/hw/scsi/mptsas.c +++ b/hw/scsi/mptsas.c @@ -36,6 +36,8 @@ #include "qapi/error.h" #include "mptsas.h" #include "migration/qemu-file-types.h" +#include "migration/qemu-file.h" +#include "qemu/error-report.h" #include "migration/vmstate.h" #include "mpi.h" @@ -1242,12 +1244,12 @@ static void *mptsas_load_request(QEMUFile *f, SCSIRequest *sreq, Error **errp) qemu_get_buffer(f, (unsigned char *)&req->scsi_io, sizeof(req->scsi_io)); n = qemu_get_be32(f); - /* TODO: add a way for SCSIBusInfo's load_request to fail, - * and fail migration instead of asserting here. - * This is just one thing (there are probably more) that must be - * fixed before we can allow NDEBUG compilation. - */ - assert(n >= 0); + if (n < 0) { + error_setg(errp, "mptsas: invalid sg list count %d in migration stream", + n); + g_free(req); + return NULL; + } pci_dma_sglist_init(&req->qsg, pci, n); for (i = 0; i < n; i++) { -- 2.54.0