From e1ae3601c42264ad77e7f753af258bb4f48b057c Mon Sep 17 00:00:00 2001 From: 21pages Date: Sat, 19 Aug 2023 20:44:54 +0800 Subject: [PATCH] encrypt return emtpy if exceed max len to avoid another encrypt Signed-off-by: 21pages --- libs/hbb_common/src/password_security.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/hbb_common/src/password_security.rs b/libs/hbb_common/src/password_security.rs index 28b32e68e..64dce1fdc 100644 --- a/libs/hbb_common/src/password_security.rs +++ b/libs/hbb_common/src/password_security.rs @@ -89,6 +89,9 @@ pub fn encrypt_str_or_original(s: &str, version: &str, max_len: usize) -> String log::error!("Duplicate encryption!"); return s.to_owned(); } + if s.bytes().len() > max_len { + return String::default(); + } if version == "00" { if let Ok(s) = encrypt(s.as_bytes(), max_len) { return version.to_owned() + &s; @@ -122,6 +125,9 @@ pub fn encrypt_vec_or_original(v: &[u8], version: &str, max_len: usize) -> Vec max_len { + return vec![]; + } if version == "00" { if let Ok(s) = encrypt(v, max_len) { let mut version = version.to_owned().into_bytes();