Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore unknown versions in version response. #22

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spdmlib/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ pub struct SpdmNegotiateInfo {
pub rsp_max_spdm_msg_size_sel: u32, // spdm 1.2
}

pub const MAX_MANAGED_BUFFER_A_SIZE: usize = 150 + 2 * MAX_SPDM_VERSION_COUNT;
pub const MAX_MANAGED_BUFFER_A_SIZE: usize = 150 + 2 * 255; // for version response, there can be more than MAX_SPDM_VERSION_COUNT versions.
pub const MAX_MANAGED_BUFFER_B_SIZE: usize =
24 + SPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_NUMBER + config::MAX_SPDM_CERT_CHAIN_DATA_SIZE;
pub const MAX_MANAGED_BUFFER_C_SIZE: usize =
Expand Down
34 changes: 25 additions & 9 deletions spdmlib/src/message/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ impl SpdmCodec for SpdmVersionResponsePayload {
u8::read(r)?; // reserved
let version_number_entry_count = u8::read(r)?;

if version_number_entry_count < 1
|| version_number_entry_count > MAX_SPDM_VERSION_COUNT as u8
{
if version_number_entry_count == 0 {
return None;
}

Expand All @@ -108,14 +106,32 @@ impl SpdmCodec for SpdmVersionResponsePayload {
},
MAX_SPDM_VERSION_COUNT,
);
for version in versions
.iter_mut()
.take(version_number_entry_count as usize)
{
*version = SpdmVersionStruct::read(r)?;

let mut version_count = 0;
let rest = r.take(version_number_entry_count as usize * 2)?;

for i in 0..version_number_entry_count {
if let Some(ver) = SpdmVersionStruct::read_bytes(&rest[i as usize * 2..]) {
if version_count < MAX_SPDM_VERSION_COUNT {
versions[version_count] = ver;
version_count += 1;
} else {
// the buffer is full now, stop for scaning more versions
break;
}
} else {
// for unknown versions,
if rest[i as usize * 2 + 1] < 0x10 {
// find a version which is lower than the 0x10 version
return None;
} else {
// for any other version, just ignore it
}
}
}

Some(SpdmVersionResponsePayload {
version_number_entry_count,
version_number_entry_count: version_count as u8,
versions,
})
}
Expand Down
Loading