Skip to content
Snippets Groups Projects
Verified Commit 4a598632 authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Fix crash when invlaid data is passed to the decryption functions

parent b452a984
No related branches found
No related tags found
No related merge requests found
Pipeline #1858 passed
......@@ -82,11 +82,15 @@ public:
{}
olm_exception(std::string func, OlmOutboundGroupSession *s)
: olm_exception(std::move(func), std::string(olm_outbound_group_session_last_error(s)))
: olm_exception(
std::move(func),
std::string(s ? olm_outbound_group_session_last_error(s) : "session == nullptr"))
{}
olm_exception(std::string func, OlmInboundGroupSession *s)
: olm_exception(std::move(func), std::string(olm_inbound_group_session_last_error(s)))
: olm_exception(
std::move(func),
std::string(s ? olm_inbound_group_session_last_error(s) : "session == nullptr"))
{}
olm_exception(std::string func, OlmSAS *s)
......
......@@ -252,12 +252,16 @@ OlmClient::decrypt_group_message(OlmInboundGroupSession *session,
const std::string &message,
uint32_t message_index)
{
// TODO handle errors
if (!session)
throw olm_exception("decrypt_group_message", session);
auto tmp_msg = create_buffer(message.size());
std::copy(message.begin(), message.end(), tmp_msg.begin());
auto plaintext_len =
olm_group_decrypt_max_plaintext_length(session, tmp_msg.data(), tmp_msg.size());
if (plaintext_len == olm_error())
throw olm_exception("olm_group_decrypt_max_plaintext_length: invalid ciphertext", session);
auto plaintext = create_buffer(plaintext_len);
tmp_msg = create_buffer(message.size());
......
......@@ -1185,6 +1185,10 @@ TEST(Encryption, PickleMegolmSessions)
std::string((char *)restored_plaintext.data.data(), restored_plaintext.data.size()));
EXPECT_EQ(std::string((char *)plaintext.data.data(), plaintext.data.size()), SECRET);
EXPECT_THROW(alice->decrypt_group_message(inbound_session.get(), ""), olm_exception);
EXPECT_THROW(alice->decrypt_group_message(nullptr, ""), olm_exception);
EXPECT_THROW(alice->decrypt_group_message(nullptr, ciphertext), olm_exception);
}
TEST(ExportSessions, InboundMegolmSessions)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment