Skip to contentSkip to conversation

scsi: fix segfault with 0-byte disk

PATCH New Paolo Bonzini 1 participant 1 message Jan 10, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: fix segfault with 0-byte disk

When a 0-sized disk is found, READ CAPACITY will return a LUN NOT READY error. However, because it returns -1 instead of zero, the HBA will call scsi_req_continue. This will typically cause a segmentation fault or an assertion failure.

---
 hw/scsi-disk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/scsi-disk.c +2 -2
index a69735b..ae9439d 100644
@@ -1682,7 +1682,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
         bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);
         if (!nb_sectors) {
             scsi_check_condition(r, SENSE_CODE(LUN_NOT_READY));
-            return -1;
+            return 0;
         }
         if ((req->cmd.buf[8] & 1) == 0 && req->cmd.lba) {
             goto illegal_request;
@@ -1751,7 +1751,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
             bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);
             if (!nb_sectors) {
                 scsi_check_condition(r, SENSE_CODE(LUN_NOT_READY));
-                return -1;
+                return 0;
             }
             if ((req->cmd.buf[14] & 1) == 0 && req->cmd.lba) {
                 goto illegal_request;
Signature · 1 line
1.8.1