From 559ed5756570ce6ffee47a14f06e1b5ac5450d0b Mon Sep 17 00:00:00 2001
From: Nicolas Werner <nicolas.werner@hotmail.de>
Date: Tue, 15 Dec 2020 18:59:08 +0100
Subject: [PATCH] Fix crash when we don't have device keys cached

---
 src/Olm.cpp | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/Olm.cpp b/src/Olm.cpp
index b05737a54..22df3911d 100644
--- a/src/Olm.cpp
+++ b/src/Olm.cpp
@@ -340,11 +340,13 @@ encrypt_group_message(const std::string &room_id, const std::string &device_id,
                                 // new member, send them the session at this index
                                 sendSessionTo[member_it->first] = {};
 
-                                for (const auto &dev : member_it->second->device_keys)
-                                        if (member_it->first != own_user_id ||
-                                            dev.first != device_id)
-                                                sendSessionTo[member_it->first].push_back(
-                                                  dev.first);
+                                if (member_it->second) {
+                                        for (const auto &dev : member_it->second->device_keys)
+                                                if (member_it->first != own_user_id ||
+                                                    dev.first != device_id)
+                                                        sendSessionTo[member_it->first].push_back(
+                                                          dev.first);
+                                }
 
                                 ++member_it;
                         } else {
-- 
GitLab