Browse Source

scsi-generic: do not snoop the output of failed commands

If a READ CAPACITY command would fail, for example s->qdev.blocksize would be
set to zero and cause a division by zero on the next use.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Paolo Bonzini 4 years ago
parent
commit
9738c65720
1 changed files with 4 additions and 1 deletions
  1. 4 1
      hw/scsi/scsi-generic.c

+ 4 - 1
hw/scsi/scsi-generic.c

@@ -288,7 +288,10 @@ static void scsi_read_complete(void * opaque, int ret)
         }
         }
     }
     }
 
 
-    if (len == 0) {
+    if (r->io_header.host_status != SCSI_HOST_OK ||
+        (r->io_header.driver_status & SG_ERR_DRIVER_TIMEOUT) ||
+        r->io_header.status != GOOD ||
+        len == 0) {
         scsi_command_complete_noio(r, 0);
         scsi_command_complete_noio(r, 0);
         goto done;
         goto done;
     }
     }