From 8b2a04eeb95212305d3a39170e1c4bc3dbe45e8a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Sun, 14 Aug 2011 14:05:49 -0700 Subject: [PATCH] scsi: do not overwrite memory on REQUEST SENSE commands with a large buffer Other scsi_target_reqops commands were careful about not using r->cmd.xfer directly, and instead always cap it to a fixed length. This was not done for REQUEST SENSE, and this patch fixes it. Reported-by: Blue Swirl Signed-off-by: Paolo Bonzini Signed-off-by: Blue Swirl --- hw/scsi-bus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 559d5a4708..c3ce7df6a1 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -292,7 +292,8 @@ static int32_t scsi_target_send_command(SCSIRequest *req, uint8_t *buf) if (req->cmd.xfer < 4) { goto illegal_request; } - r->len = scsi_device_get_sense(r->req.dev, r->buf, req->cmd.xfer, + r->len = scsi_device_get_sense(r->req.dev, r->buf, + MIN(req->cmd.xfer, sizeof r->buf), (req->cmd.buf[1] & 1) == 0); break; default: -- GitLab