diff mbox series

[v5,05/13] scsi: sr: need to check the result of scsi_execute in sr_do_ioctl

Message ID 1571387071-28853-6-git-send-email-zhengbin13@huawei.com (mailing list archive)
State Changes Requested
Headers show
Series scsi: core: fix uninit-value access of variable sshdr | expand

Commit Message

Zheng Bin Oct. 18, 2019, 8:24 a.m. UTC
Like sd_pr_command, before use sshdr, we need to check the result
of scsi_execute, also need to check whether sshdr is valid.

Signed-off-by: zhengbin <zhengbin13@huawei.com>
---
 drivers/scsi/sr_ioctl.c | 6 ++++++
 1 file changed, 6 insertions(+)

--
2.7.4
diff mbox series

Patch

diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c
index ffcf902..7672fc1 100644
--- a/drivers/scsi/sr_ioctl.c
+++ b/drivers/scsi/sr_ioctl.c
@@ -206,6 +206,12 @@  int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)

 	/* Minimal error checking.  Ignore cases we know about, and report the rest. */
 	if (driver_byte(result) != 0) {
+		if (driver_byte(result) != DRIVER_SENSE ||
+		    !scsi_sense_valid(sshdr)) {
+			err = -EIO;
+			goto out;
+		}
+
 		switch (sshdr->sense_key) {
 		case UNIT_ATTENTION:
 			SDev->changed = 1;