From 2276af0a8c6e80fc63ab020508878dfaa9595c74 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Thu, 14 Apr 2022 07:45:57 -0700 Subject: uwb(uci-rust): Fix error checking in build_set_app_config_cmd Len of app_configs should be checked against the parsed tlv len, not |no_of_params|. Bug: 229246228 Test: Manual Tests Change-Id: I20d1e7711be076327a2ef8b8b9aa1dfcc7deb914 --- src/rust/uci/uci_hmsgs.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/rust/uci/uci_hmsgs.rs b/src/rust/uci/uci_hmsgs.rs index 9b2f57d..538b679 100644 --- a/src/rust/uci/uci_hmsgs.rs +++ b/src/rust/uci/uci_hmsgs.rs @@ -71,15 +71,19 @@ pub fn build_set_app_config_cmd( no_of_params: u32, mut app_configs: &[u8], ) -> Result { - if no_of_params != app_configs.len().try_into()? { - return Err(UwbErr::InvalidArgs); - } let mut tlvs = Vec::new(); + let received_tlvs_len = app_configs.len(); + let mut parsed_tlvs_len = 0; for _ in 0..no_of_params { let tlv = AppConfigTlv::parse(app_configs)?; - app_configs = &app_configs[tlv.v.len() + 2..]; + app_configs = app_configs.get(tlv.v.len() + 2..).ok_or(UwbErr::InvalidArgs)?; + parsed_tlvs_len += tlv.v.len() + 2; tlvs.push(tlv); } + if parsed_tlvs_len != received_tlvs_len { + error!("Parsed TLV len: {:?}, received len: {:?}", parsed_tlvs_len, received_tlvs_len); + return Err(UwbErr::InvalidArgs); + } Ok(SessionSetAppConfigCmdBuilder { session_id, tlvs }) } -- cgit v1.2.3