diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2017-05-13 11:14:16 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2017-05-13 11:14:16 +0300 |
commit | 548f1be92197f393ceb3d2d0cb42d911d40e03a6 (patch) | |
tree | 35ffe6501a249314910fc7c6592af6ac6d4b47c4 /protocols/JabberG/src/jabber_omemo.cpp | |
parent | 7953fbce7b40c79c0471661b4a6b81792c5e5f5b (diff) |
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)
Diffstat (limited to 'protocols/JabberG/src/jabber_omemo.cpp')
-rwxr-xr-x | protocols/JabberG/src/jabber_omemo.cpp | 29 |
1 files 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<MCONTACT, std::map<unsigned int, omemo::omemo_session_jabber_internal_ptrs> >*)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);
|