From 66271877dce9627e4dba935375938e5fa8597f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Sat, 16 Mar 2024 10:28:25 +0100 Subject: [PATCH] Return an error if the IKM list ID is invalid --- src/error.rs | 2 ++ src/storage.rs | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/error.rs b/src/error.rs index b4b8cf4..3151807 100644 --- a/src/error.rs +++ b/src/error.rs @@ -18,6 +18,8 @@ pub enum Error { ParsingEncodedDataInvalidIkmId(Vec), #[error("parsing error: encoded data: invalid IKM length{0}")] ParsingEncodedDataInvalidIkmLen(usize), + #[error("parsing error: encoded data: invalid IKM list id: {0:?}")] + ParsingEncodedDataInvalidIkmListId(Vec), #[error("parsing error: encoded data: invalid IKM list length{0}")] ParsingEncodedDataInvalidIkmListLen(usize), #[error("parsing error: encoded data: invalid number of parts: got {1} instead of {0}")] diff --git a/src/storage.rs b/src/storage.rs index e2f21bb..83356a4 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -53,6 +53,9 @@ pub(crate) fn decode_ikm_list(data: &str) -> Result { return Err(Error::ParsingEncodedDataInvalidIkmListLen(v.len())); } let id_data = decode_data(v[0])?; + if id_data.len() != 4 { + return Err(Error::ParsingEncodedDataInvalidIkmListId(id_data)); + } let id_counter = CounterId::from_le_bytes(id_data[0..4].try_into().unwrap()); let mut ikm_lst = Vec::with_capacity(v.len() - 1); for ikm_str in &v[1..] {