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

Add length check when take(rsp_length) #96

Merged
merged 1 commit into from
May 30, 2024
Merged
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
25 changes: 15 additions & 10 deletions spdmlib/src/message/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,22 @@ impl Codec for VendorDefinedRspPayloadStruct {

fn read(r: &mut Reader) -> Option<VendorDefinedRspPayloadStruct> {
let rsp_length = u16::read(r)?;
let mut vendor_defined_rsp_payload = [0u8; MAX_SPDM_VENDOR_DEFINED_PAYLOAD_SIZE];
for d in vendor_defined_rsp_payload
.iter_mut()
.take(rsp_length as usize)
{
*d = u8::read(r)?;
if rsp_length as usize > MAX_SPDM_VENDOR_DEFINED_PAYLOAD_SIZE {
log::error!("invalid rsp length!!!\n");
None
} else {
let mut vendor_defined_rsp_payload = [0u8; MAX_SPDM_VENDOR_DEFINED_PAYLOAD_SIZE];
for d in vendor_defined_rsp_payload
.iter_mut()
.take(rsp_length as usize)
{
*d = u8::read(r)?;
}
Some(VendorDefinedRspPayloadStruct {
rsp_length,
vendor_defined_rsp_payload,
})
}
Some(VendorDefinedRspPayloadStruct {
rsp_length,
vendor_defined_rsp_payload,
})
}
}

Expand Down
Loading