From 89db2e536c01a0d8d96bed915232a653dd6d3863 Mon Sep 17 00:00:00 2001 From: David Mulder Date: Thu, 22 Aug 2024 12:54:32 -0600 Subject: [PATCH] Always normalize cache inputs to lowercase This prevents mixed case issues when storing/ retrieving data from the cache. Signed-off-by: David Mulder Reviewed-by: Alexander Bokovoy --- rust/himmelblaud/src/cache.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/rust/himmelblaud/src/cache.rs b/rust/himmelblaud/src/cache.rs index ad1e44c9c5c..12a2cd97640 100644 --- a/rust/himmelblaud/src/cache.rs +++ b/rust/himmelblaud/src/cache.rs @@ -48,7 +48,8 @@ impl BasicCache { } fn fetch_str(&self, key: &str) -> Option { - let exists = match self.tdb.exists(key) { + let key = key.to_string().to_lowercase(); + let exists = match self.tdb.exists(&key) { Ok(exists) => exists, Err(e) => { DBG_ERR!("Failed to fetch {}: {:?}", key, e); @@ -56,7 +57,7 @@ impl BasicCache { } }; if exists { - match self.tdb.fetch(key) { + match self.tdb.fetch(&key) { Ok(val) => Some(val), Err(e) => { DBG_ERR!("Failed to fetch {}: {:?}", key, e); @@ -72,7 +73,8 @@ impl BasicCache { where T: for<'de> Deserialize<'de>, { - match self.fetch_str(key) { + let key = key.to_string().to_lowercase(); + match self.fetch_str(&key) { Some(val) => match json_from_slice::(val.as_bytes()) { Ok(res) => Some(res), Err(e) => { @@ -91,6 +93,7 @@ impl BasicCache { key: &str, val: &[u8], ) -> Result<(), Box> { + let key = key.to_string().to_lowercase(); match self.tdb.transaction_start() { Ok(start) => { if !start { @@ -104,7 +107,7 @@ impl BasicCache { } }; - let res = match self.tdb.store(key, val, None) { + let res = match self.tdb.store(&key, val, None) { Ok(res) => Some(res), Err(e) => { DBG_ERR!("Unable to persist {}: {:?}", key, e); @@ -145,6 +148,7 @@ impl BasicCache { where T: Serialize, { + let key = key.to_string().to_lowercase(); let val_bytes = match json_to_vec(&val) { Ok(val_bytes) => val_bytes, Err(e) => { @@ -152,7 +156,7 @@ impl BasicCache { return Err(Box::new(NT_STATUS_UNSUCCESSFUL)); } }; - self.store_bytes(key, &val_bytes) + self.store_bytes(&key, &val_bytes) } fn keys(&self) -> Result, Box> { @@ -241,6 +245,7 @@ impl UidCache { upn: &str, ) -> Result<(), Box> { let key = format!("{}", uid); + let upn = upn.to_string().to_lowercase(); self.cache.store_bytes(&key, upn.as_bytes()) } -- 2.47.3