Skip to content

Commit ce65818

Browse files
Fix warnings and improve robustness of scsiapi_linux.c
1 parent 815924b commit ce65818

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

scsiapi/scsiapi_linux.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ struct scsi_device_info * scsi_enumerate(const char * vendor, const char * produ
8181
/*-------------------------------------------------*\
8282
| Read the model string and close the model file |
8383
\*-------------------------------------------------*/
84-
read(sg_model_fd, sg_model_buf, 512);
84+
if(read(sg_model_fd, sg_model_buf, 512) < 0)
85+
{
86+
close(sg_model_fd);
87+
close(sg_vendor_fd);
88+
break;
89+
}
8590
close(sg_model_fd);
8691

8792
for(unsigned int i = 0; i < strlen(sg_model_buf); i++)
@@ -96,7 +101,11 @@ struct scsi_device_info * scsi_enumerate(const char * vendor, const char * produ
96101
/*-------------------------------------------------*\
97102
| Read the vendor string and close the vendor file |
98103
\*-------------------------------------------------*/
99-
read(sg_vendor_fd, sg_vendor_buf, 512);
104+
if(read(sg_vendor_fd, sg_vendor_buf, 512) < 0)
105+
{
106+
close(sg_vendor_fd);
107+
break;
108+
}
100109
close(sg_vendor_fd);
101110

102111
for(unsigned int i = 0; i < strlen(sg_vendor_buf); i++)

0 commit comments

Comments
 (0)