crytpo: Get the session from the list of sessions in a safe manner.

master
Damir Jelić 2020-10-08 15:56:17 +02:00
parent d96c9f85a1
commit 473e49252e
1 changed files with 9 additions and 3 deletions

View File

@ -365,9 +365,15 @@ impl ReadOnlyDevice {
return Err(EventError::MissingSenderKey.into());
};
let mut session = if let Some(s) = store.get_sessions(sender_key).await? {
let session = &s.lock().await[0];
session.clone()
let session = if let Some(s) = store.get_sessions(sender_key).await? {
let sessions = s.lock().await;
sessions.get(0).cloned()
} else {
None
};
let mut session = if let Some(s) = session {
s
} else {
warn!(
"Trying to encrypt a Megolm session for user {} on device {}, \