Skip to contentSkip to conversation

scsi: handle the special parameters

PATCH In review linzhecheng 2 participants 2 messages Jan 15, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: handle the special parameters

scsi_disk_emulate_command calls
scsi_build_sense(NULL, 0, outbuf, r->buflen,

                                  (req->cmd.buf[1] & 1) == 0);

But scsi_convert_sense doesn't handle the case when in_buf is NULL or in_len is 0, which will lead to segfault.

---
 scsi/utils.c | 4 ++++
 1 file changed, 4 insertions(+)
scsi/utils.c +4 -0
index ddae650a99..b769e80c12 100644
@@ -322,6 +322,10 @@ int scsi_convert_sense(uint8_t *in_buf, int in_len,
     SCSISense sense;
     bool fixed_in;
 
+    if (!in_buf || !in_len) {
+        return 0;
+    }
+
     fixed_in = (in_buf[0] & 2) == 0;
     if (in_len && fixed == fixed_in) {
         memcpy(buf, in_buf, MIN(len, in_len));
Signature · 1 line
2.12.2.windows.2
#1 lore raw
Quoted 6 lines · linzhecheng

scsi_disk_emulate_command calls
scsi_build_sense(NULL, 0, outbuf, r->buflen,

                                  (req->cmd.buf[1] & 1) == 0);

But scsi_convert_sense doesn't handle the case when in_buf is NULL or in_len is 0, which will lead to segfault.

This is already fixed in my last pull request.

Paolo

Quoted 21 lines
---
 scsi/utils.c | 4 ++++
 1 file changed, 4 insertions(+)
scsi/utils.c +4 -0
index ddae650a99..b769e80c12 100644
@@ -322,6 +322,10 @@ int scsi_convert_sense(uint8_t *in_buf, int in_len,
     SCSISense sense;
     bool fixed_in;
 
+    if (!in_buf || !in_len) {
+        return 0;
+    }
+
     fixed_in = (in_buf[0] & 2) == 0;
     if (in_len && fixed == fixed_in) {
         memcpy(buf, in_buf, MIN(len, in_len));