crypto: Fix overflow in should_upload_keys, bail out if uploaded keys > max uploaded

master
Devin R 2020-06-16 18:07:13 -04:00
parent f35fbdf8b0
commit 15191d0230
1 changed files with 6 additions and 0 deletions

View File

@ -215,6 +215,12 @@ impl OlmMachine {
match &self.uploaded_signed_key_count { match &self.uploaded_signed_key_count {
Some(count) => { Some(count) => {
let max_keys = self.account.max_one_time_keys().await as u64; let max_keys = self.account.max_one_time_keys().await as u64;
// If there are more keys already uploaded than max_key / 2
// bail out returning false, this also avoids overflow.
if count.load(Ordering::Relaxed) > (max_keys / 2) {
return false;
}
let key_count = (max_keys / 2) - count.load(Ordering::Relaxed); let key_count = (max_keys / 2) - count.load(Ordering::Relaxed);
key_count > 0 key_count > 0
} }