Skip to content

Commit

Permalink
Update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 24, 2024
1 parent b15b315 commit a8627b8
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions cpp/devices/mode_page_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ string mode_page_util::ModeSelect(scsi_command cmd, cdb_t cdb, span<const uint8_
}

const int block_descriptor_length = GetInt16(buf, 6);
if (block_descriptor_length && length < 16) {
if (length < block_descriptor_length + 8) {
throw scsi_exception(sense_key::illegal_request, asc::parameter_list_length_error);

}

if (block_descriptor_length && GetInt16(buf, 14) != sector_size) {
if (block_descriptor_length && length < 16 && GetInt16(buf, 14) != sector_size) {
warn(SECTOR_SIZE_WARNING);
throw scsi_exception(sense_key::illegal_request, asc::invalid_field_in_parameter_list);
}
Expand All @@ -60,12 +59,11 @@ string mode_page_util::ModeSelect(scsi_command cmd, cdb_t cdb, span<const uint8_
}

const int block_descriptor_length = buf[3];
if (block_descriptor_length && length < 12) {
if (length < block_descriptor_length + 4) {
throw scsi_exception(sense_key::illegal_request, asc::parameter_list_length_error);

}

if (block_descriptor_length && GetInt16(buf, 10) != sector_size) {
if (block_descriptor_length && length < 12 && GetInt16(buf, 10) != sector_size) {
warn(SECTOR_SIZE_WARNING);
throw scsi_exception(sense_key::illegal_request, asc::invalid_field_in_parameter_list);
}
Expand Down

0 comments on commit a8627b8

Please sign in to comment.