diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2021-07-26 18:57:46 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2021-07-26 18:59:21 +0200 |
commit | 6222ae88ce08c289ad67058dd3200bd1d5950072 (patch) | |
tree | d5912d87e845ead1fac08b20a635d3e97975e442 | |
parent | Remove version checks for unsupported Qt versions (diff) | |
download | nheko-6222ae88ce08c289ad67058dd3200bd1d5950072.tar.xz |
Fix crash on invalid utf8 in decrypted events
-rw-r--r-- | src/Olm.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/Olm.cpp b/src/Olm.cpp index 81121443..d20bf9a4 100644 --- a/src/Olm.cpp +++ b/src/Olm.cpp @@ -1048,24 +1048,24 @@ decryptEvent(const MegolmSessionIndex &index, return {DecryptionErrorCode::DecryptionFailed, e.what(), std::nullopt}; } - // Add missing fields for the event. - json body = json::parse(msg_str); - body["event_id"] = event.event_id; - body["sender"] = event.sender; - body["origin_server_ts"] = event.origin_server_ts; - body["unsigned"] = event.unsigned_data; + try { + // Add missing fields for the event. + json body = json::parse(msg_str); + body["event_id"] = event.event_id; + body["sender"] = event.sender; + body["origin_server_ts"] = event.origin_server_ts; + body["unsigned"] = event.unsigned_data; - // relations are unencrypted in content... - mtx::common::add_relations(body["content"], event.content.relations); + // relations are unencrypted in content... + mtx::common::add_relations(body["content"], event.content.relations); - mtx::events::collections::TimelineEvent te; - try { + mtx::events::collections::TimelineEvent te; mtx::events::collections::from_json(body, te); + + return {std::nullopt, std::nullopt, std::move(te.data)}; } catch (std::exception &e) { return {DecryptionErrorCode::ParsingFailed, e.what(), std::nullopt}; } - - return {std::nullopt, std::nullopt, std::move(te.data)}; } crypto::Trust |