Skip to content

Commit 930195c

Browse files
committed
MSD: check LUN number
1 parent 919a73e commit 930195c

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

firmware/hw_layer/mass_storage/mass_storage_device.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,15 @@ void MassStorageController::ThreadTask() {
9999
}
100100

101101
if (cbwValid(m_cbw, status) && cbwMeaningful(m_cbw)) {
102-
auto target = &m_luns[m_cbw.lun].target;
103-
if (SCSI_SUCCESS == scsiExecCmd(target, m_cbw.cmd_data)) {
104-
sendCsw(CSW_STATUS_PASSED, 0);
105-
} else {
106-
sendCsw(CSW_STATUS_FAILED, scsiResidue(target));
102+
// Get the LUN from the incoming CBW packet
103+
uint8_t target_lun = m_cbw.lun & 0x0F; // Mask out reserved bits
104+
if (target_lun <= USB_MSD_LUN_COUNT) {
105+
auto target = &m_luns[target_lun].target;
106+
if (SCSI_SUCCESS == scsiExecCmd(target, m_cbw.cmd_data)) {
107+
sendCsw(CSW_STATUS_PASSED, 0);
108+
} else {
109+
sendCsw(CSW_STATUS_FAILED, scsiResidue(target));
110+
}
107111
}
108112
} else {
109113
// ignore incorrect CBW

0 commit comments

Comments
 (0)