From 72c6977b964db4de9d0233643493d3bd73687e34 Mon Sep 17 00:00:00 2001 From: "Yang, Longlong" Date: Tue, 12 Dec 2023 01:09:23 -0500 Subject: [PATCH] check total_elements before using it. fix #172 Signed-off-by: Yang, Longlong --- spdmlib/src/common/opaque.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spdmlib/src/common/opaque.rs b/spdmlib/src/common/opaque.rs index 270986ca..94632cbb 100644 --- a/spdmlib/src/common/opaque.rs +++ b/spdmlib/src/common/opaque.rs @@ -509,6 +509,11 @@ impl SpdmCodec for SecuredMessageDMTFVersionSelection { ) -> Option { let secured_message_general_opaque_data_header = SecuredMessageGeneralOpaqueDataHeader::spdm_read(context, r)?; + if secured_message_general_opaque_data_header.total_elements as usize + > MAX_OPAQUE_LIST_ELEMENTS_COUNT + { + return None; + } let mut opaque_element_dmtf_version_selection_list = [OpaqueElementDMTFVersionSelection::default(); MAX_OPAQUE_LIST_ELEMENTS_COUNT]; for d in opaque_element_dmtf_version_selection_list