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. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
5b5d34ec98
commit
0369f06f74
|
@ -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);
|
bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);
|
||||||
if (!nb_sectors) {
|
if (!nb_sectors) {
|
||||||
scsi_check_condition(r, SENSE_CODE(LUN_NOT_READY));
|
scsi_check_condition(r, SENSE_CODE(LUN_NOT_READY));
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
if ((req->cmd.buf[8] & 1) == 0 && req->cmd.lba) {
|
if ((req->cmd.buf[8] & 1) == 0 && req->cmd.lba) {
|
||||||
goto illegal_request;
|
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);
|
bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);
|
||||||
if (!nb_sectors) {
|
if (!nb_sectors) {
|
||||||
scsi_check_condition(r, SENSE_CODE(LUN_NOT_READY));
|
scsi_check_condition(r, SENSE_CODE(LUN_NOT_READY));
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
if ((req->cmd.buf[14] & 1) == 0 && req->cmd.lba) {
|
if ((req->cmd.buf[14] & 1) == 0 && req->cmd.lba) {
|
||||||
goto illegal_request;
|
goto illegal_request;
|
||||||
|
|
Loading…
Reference in a new issue