summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-07-30 12:44:08 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2021-07-30 12:44:08 +0200
commite7877ae5af533f75ee8fade52f968c453df7c201 (patch)
tree8b6b4c80f2565f9e38fa7876847516c81e87a013
parentLog how many rooms we loaded (diff)
downloadnheko-e7877ae5af533f75ee8fade52f968c453df7c201.tar.xz
Fix crash when we don't have keys for other device when receiving an olm message from it
-rw-r--r--src/Olm.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/Olm.cpp b/src/Olm.cpp
index d421e336..e3ca1c34 100644
--- a/src/Olm.cpp
+++ b/src/Olm.cpp
@@ -286,11 +286,17 @@ handle_olm_message(const OlmMessage &msg, const UserKeyCache &otherUserDeviceKey
 
                         bool from_their_device = false;
                         for (auto [device_id, key] : otherUserDeviceKeys.device_keys) {
-                                if (key.keys.at("curve25519:" + device_id) == msg.sender_key) {
-                                        if (key.keys.at("ed25519:" + device_id) == sender_ed25519) {
-                                                from_their_device = true;
-                                                break;
-                                        }
+                                auto c_key = key.keys.find("curve25519:" + device_id);
+                                auto e_key = key.keys.find("ed25519:" + device_id);
+
+                                if (c_key == key.keys.end() || e_key == key.keys.end()) {
+                                        nhlog::crypto()->warn(
+                                          "Skipping device {} as we have no keys for it.",
+                                          device_id);
+                                } else if (c_key->second == msg.sender_key &&
+                                           e_key->second == sender_ed25519) {
+                                        from_their_device = true;
+                                        break;
                                 }
                         }
                         if (!from_their_device) {