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

This commit is contained in:
Damir Jelić 2020-10-08 15:56:17 +02:00
parent d96c9f85a1
commit 473e49252e

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 {}, \