imsm: fix reading scsi serial

Improve error detection after SG_IO ioctl. Checking only the return
value and response length is insufficient and leads to anomalies if a
drive does not have a serial number.

Reported-by: NeilBrown <neilb@suse.com>
Tested-by: NeilBrown <neilb@suse.com>
Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
This commit is contained in:
Artur Paszkiewicz 2017-11-02 16:10:57 +01:00 committed by Jes Sorensen
parent 3bc6f786e1
commit 01a052b9c1
1 changed files with 3 additions and 0 deletions

View File

@ -46,6 +46,9 @@ int scsi_get_serial(int fd, void *buf, size_t buf_len)
if (rv)
return rv;
if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK)
return -1;
rsp_len = rsp_buf[3];
if (!rsp_len || buf_len < rsp_len)