From d00fbb98822781497c86da88b8be378f14cbb97f Mon Sep 17 00:00:00 2001 From: Alex Page Date: Fri, 23 Jun 2023 16:59:02 -0400 Subject: [PATCH] Add upfront length checks to confid --- src/confid/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/confid/mod.rs b/src/confid/mod.rs index 397a938..63dc290 100644 --- a/src/confid/mod.rs +++ b/src/confid/mod.rs @@ -21,6 +21,12 @@ pub enum ConfirmationIdError { } pub fn generate(installation_id: &str) -> Result { + if installation_id.len() < 54 { + return Err(ConfirmationIdError::TooShort); + } + if installation_id.len() > 54 { + return Err(ConfirmationIdError::TooLarge); + } let inst_id = CString::new(installation_id).unwrap(); let conf_id = [0u8; 49]; let result = unsafe { black_box::generate(inst_id.as_ptr(), conf_id.as_ptr() as *mut i8) };