From 548f1be92197f393ceb3d2d0cb42d911d40e03a6 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 13 May 2017 11:14:16 +0300 Subject: jabber: omemo: crash fix fixed crash and added error message if pre_key_signal_message_deserialize failed fixed logic for picking remote prekey (it was 1/prekey_count possibility of inifinite loop or no prekey) --- protocols/JabberG/src/jabber_omemo.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp index 96313ab930..2dcbcada98 100755 --- a/protocols/JabberG/src/jabber_omemo.cpp +++ b/protocols/JabberG/src/jabber_omemo.cpp @@ -1201,10 +1201,11 @@ namespace omemo { * registration ID, if it was successfully retrieved. * @return 0 on success, negative on failure */ - uint32_t *id = (uint32_t*)mir_alloc(sizeof(uint32_t)); +// uint32_t *id = (uint32_t*)mir_alloc(sizeof(uint32_t)); signal_store_backend_user_data* data = (signal_store_backend_user_data*)user_data; - *id = data->proto->m_omemo.GetOwnDeviceId(); - registration_id = id; +/* *id = data->proto->m_omemo.GetOwnDeviceId(); + registration_id = id; */ + *registration_id = data->proto->m_omemo.GetOwnDeviceId(); return 0; } @@ -1590,7 +1591,23 @@ void CJabberProto::OmemoHandleMessage(HXML node, LPCTSTR jid, time_t msgTime) } signal_buffer *decrypted_key = NULL; pre_key_signal_message *pm; - pre_key_signal_message_deserialize(&pm, encrypted_key, encrypted_key_len, omemo::global_context); + //TODO: cleanup before return on error + { + int ret = pre_key_signal_message_deserialize(&pm, encrypted_key, encrypted_key_len, omemo::global_context); + switch (ret) + { + case SG_SUCCESS: + break; + case SG_ERR_INVALID_PROTO_BUF: + debugLogA("Jabber OMEMO: error: pre_key_signal_message_deserialize failed SG_ERR_INVALID_PROTO_BUF"); + return; + break; + default: + debugLogA("Jabber OMEMO: error: pre_key_signal_message_deserialize failed with unknown error"); + return; + break; + } + } if (pm) { int ret = session_cipher_decrypt_pre_key_signal_message((*(std::map >*)m_omemo.sessions_internal)[hContact][sender_dev_id_int].cipher, pm, 0, &decrypted_key); @@ -1623,6 +1640,8 @@ void CJabberProto::OmemoHandleMessage(HXML node, LPCTSTR jid, time_t msgTime) return; break; default: + debugLogA("Jabber OMEMO: error: session_cipher_decrypt_pre_key_signal_message failed with unknown error"); + return; break; } } @@ -2042,7 +2061,7 @@ void CJabberProto::OmemoOnIqResultGetBundle(HXML iqNode, CJabberIqInfo *pInfo) unsigned char key_num = 0; while(key_num == 0) Utils_GetRandom(&key_num, 1); - key_num = key_num % (XmlGetChildCount(prekeys) + 1); + key_num = (key_num % (XmlGetChildCount(prekeys))) + 1; wchar_t key_num_str[4]; mir_snwprintf(key_num_str, 3, L"%d", key_num); -- cgit v1.2.3