Skip to content

Commit

Permalink
Fix length calculation in scsi_command_util::ModeSelect
Browse files Browse the repository at this point in the history
OpenVMS Alpha sends a strange ModeSelect payload, apparently one byte
too large. This was 'fixed' by a (wrong) length calculation in PiSCSI#1405, breaking PiSCSI#1427.

This PR
- fixes the wrong length calculation
- improves the loop test in scsi_command_util::ModeSelect to prevent a
  buffer overflow. (Remaining length was checked for > 0, but buffer
  access is at offset and offset + 1, effectively requiring 2 bytes.)
- the loop test fix makes PiSCSI#1402 pass
- adds a testcase for PiSCSI#1402
- adds a testcase for PiSCSI#1427

Fixes issue PiSCSI#1427

Signed-off-by: Klaus Kämpf <kkaempf@gmail.com>
  • Loading branch information
kkaempf committed Aug 9, 2024
1 parent ee7c0e5 commit 44162b4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cpp/devices/scsi_command_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ string scsi_command_util::ModeSelect(scsi_command cmd, cdb_t cdb, span<const uin
bool has_valid_page_code = (length == 0);

// Parse the pages
while (length > 0) {
// expect (remaining) length > 1 because we access buf[offset+1] below
while (length > 1) {
// Format device page
if (const int page = buf[offset]; page == 0x03) {
if (length < 14) {
Expand Down

0 comments on commit 44162b4

Please sign in to comment.