scsi: ses: check return code from ses_recv_diag()
authorHannes Reinecke <hare@suse.de>
Tue, 15 Aug 2017 08:21:41 +0000 (10:21 +0200)
committerMartin K. Petersen <martin.petersen@oracle.com>
Fri, 25 Aug 2017 02:28:58 +0000 (22:28 -0400)
We should be checking the return code from ses_recv_diag() to avoid
accessing invalid data.

Signed-off-by: Hannes Reinecke <hare@suse.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/ses.c

index f1cdf32d7514120b31515ddf2901960d4f766694..2a651b2063a2332ac6281b30ac90594d4895a627 100644 (file)
@@ -179,7 +179,8 @@ static unsigned char *ses_get_page2_descriptor(struct enclosure_device *edev,
        unsigned char *type_ptr = ses_dev->page1_types;
        unsigned char *desc_ptr = ses_dev->page2 + 8;
 
-       ses_recv_diag(sdev, 2, ses_dev->page2, ses_dev->page2_len);
+       if (ses_recv_diag(sdev, 2, ses_dev->page2, ses_dev->page2_len) < 0)
+               return NULL;
 
        for (i = 0; i < ses_dev->page1_num_types; i++, type_ptr += 4) {
                for (j = 0; j < type_ptr[1]; j++) {