diff --git a/spdmlib/src/common/mod.rs b/spdmlib/src/common/mod.rs index 760f94d..fba4cdc 100644 --- a/spdmlib/src/common/mod.rs +++ b/spdmlib/src/common/mod.rs @@ -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 = diff --git a/spdmlib/src/message/version.rs b/spdmlib/src/message/version.rs index 4f6621d..0726620 100644 --- a/spdmlib/src/message/version.rs +++ b/spdmlib/src/message/version.rs @@ -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; } @@ -108,14 +106,25 @@ 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; + + for _ in 0..version_number_entry_count { + if let Some(ver) = SpdmVersionStruct::read(r) { + 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, just ignore it! + } } + Some(SpdmVersionResponsePayload { - version_number_entry_count, + version_number_entry_count: version_count as u8, versions, }) }