diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2018-03-27 04:28:35 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2018-03-27 04:28:35 +0300 |
commit | 8150d61a086cdf72b5aadf585c05b7db5ce6b511 (patch) | |
tree | ec04f6461929c1d9b977aad633a98897005b508a /protocols/JabberG/src | |
parent | 4b425310e632cd9f6fd6c7d76089d8889872bcb4 (diff) |
protocols: jabber: omemo
- fix possible crash on early session negotiation
Diffstat (limited to 'protocols/JabberG/src')
-rwxr-xr-x | protocols/JabberG/src/jabber_omemo.cpp | 45 | ||||
-rwxr-xr-x | protocols/JabberG/src/jabber_proto.h | 2 | ||||
-rwxr-xr-x | protocols/JabberG/src/jabber_thread.cpp | 3 |
3 files changed, 25 insertions, 25 deletions
diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp index 317d299ff5..4a9f876d66 100755 --- a/protocols/JabberG/src/jabber_omemo.cpp +++ b/protocols/JabberG/src/jabber_omemo.cpp @@ -1580,63 +1580,62 @@ void CJabberProto::OmemoPutMessageToIncommingQueue(HXML node, const wchar_t *jid void CJabberProto::OmemoHandleMessageQueue()
{
- for (std::list<omemo::outgoing_message>::iterator i = ((omemo::message_queue*)m_omemo.message_queue_internal)->outgoing_messages.begin(),
- end = ((omemo::message_queue*)m_omemo.message_queue_internal)->outgoing_messages.end(); i != end; ++i)
+ for (auto i : ((omemo::message_queue*)m_omemo.message_queue_internal)->outgoing_messages)
{
- SendMsg(i->hContact, i->unused_unknown, i->pszSrc);
- mir_free(i->pszSrc);
+ SendMsg(i.hContact, i.unused_unknown, i.pszSrc);
+ mir_free(i.pszSrc);
}
((omemo::message_queue*)m_omemo.message_queue_internal)->outgoing_messages.clear();
- for (std::list<omemo::incomming_message>::iterator i = ((omemo::message_queue*)m_omemo.message_queue_internal)->incomming_messages.begin(),
- end = ((omemo::message_queue*)m_omemo.message_queue_internal)->incomming_messages.end(); i != end; ++i)
+ std::list<omemo::incomming_message> tmp = ((omemo::message_queue*)m_omemo.message_queue_internal)->incomming_messages;
+ ((omemo::message_queue*)m_omemo.message_queue_internal)->incomming_messages.clear();
+ for (auto i : tmp)
{
- OmemoHandleMessage(i->node, i->jid, i->msgTime);
- xmlFree(i->node);
- mir_free(i->jid);
+ if (!OmemoHandleMessage(i.node, i.jid, i.msgTime))
+ OmemoPutMessageToIncommingQueue(i.node, i.jid, i.msgTime);
+ xmlFree(i.node);
+ mir_free(i.jid);
}
- ((omemo::message_queue*)m_omemo.message_queue_internal)->incomming_messages.clear();
}
DWORD JabberGetLastContactMessageTime(MCONTACT hContact);
-void CJabberProto::OmemoHandleMessage(HXML node, wchar_t *jid, time_t msgTime)
+bool CJabberProto::OmemoHandleMessage(HXML node, wchar_t *jid, time_t msgTime)
{
MCONTACT hContact = HContactFromJID(jid);
if (!OmemoCheckSession(hContact))
{
- OmemoPutMessageToIncommingQueue(node, jid, msgTime);
debugLogA("Jabber OMEMO: sessions not yet created, session creation launched");
- return;
+ return false;
}
HXML header_node = XmlGetChild(node, L"header");
if (!header_node)
{
debugLogA("Jabber OMEMO: error: omemo message does not contain header");
- return;
+ return true; //this should never happen
}
HXML payload_node = XmlGetChild(node, L"payload");
if (!payload_node)
{
debugLogA("Jabber OMEMO: omemo message does not contain payload, it's may be \"KeyTransportElement\" which is currently unused by our implementation");
- return; //this is "KeyTransportElement" which is currently unused
+ return true; //this is "KeyTransportElement" which is currently unused
}
const wchar_t *payload_base64w = XmlGetText(payload_node);
if (!payload_base64w)
{
debugLogA("Jabber OMEMO: error: failed to get payload data");
- return;
+ return true; //this should never happen
}
const wchar_t *iv_base64 = XmlGetText(XmlGetChild(header_node, L"iv"));
if (!iv_base64)
{
Netlib_Log(nullptr, "Jabber OMEMO: error: failed to get iv data");
- return;
+ return true;
}
const wchar_t *sender_dev_id = XmlGetAttrValue(header_node, L"sid");
if (!sender_dev_id)
{
debugLogA("Jabber OMEMO: error: failed to get sender device id");
- return;
+ return true;
}
char *sender_device_id_a = mir_u2a(sender_dev_id);
DWORD sender_dev_id_int = strtoul(sender_device_id_a, nullptr, 10);
@@ -1646,9 +1645,8 @@ void CJabberProto::OmemoHandleMessage(HXML node, wchar_t *jid, time_t msgTime) || !(*(std::map<MCONTACT, std::map<unsigned int, omemo::omemo_session_jabber_internal_ptrs> >*)m_omemo.sessions_internal)[hContact][sender_dev_id_int].store_context)
{
OmemoCheckSession(hContact); //this should not normally happened
- OmemoPutMessageToIncommingQueue(node, jid, msgTime);
debugLogA("Jabber OMEMO: bug: omemo session does not exist or broken");
- return;
+ return false;
}
HXML key_node;
DWORD own_id = m_omemo.GetOwnDeviceId();
@@ -1668,7 +1666,7 @@ void CJabberProto::OmemoHandleMessage(HXML node, wchar_t *jid, time_t msgTime) if (!encrypted_key_base64)
{
debugLogA("Jabber OMEMO: message does not have decryption key for our device");
- return; //node does not contain key for our device
+ return true; //node does not contain key for our device
}
size_t encrypted_key_len;
unsigned char *encrypted_key;
@@ -1794,7 +1792,7 @@ void CJabberProto::OmemoHandleMessage(HXML node, wchar_t *jid, time_t msgTime) if(!decrypted)
{
debugLogA("Jabber OMEMO: error: failed to decrypt incomming message");
- return; //TODO: cleanup
+ return true; //TODO: cleanup
}
char *out = nullptr;
{
@@ -1836,7 +1834,7 @@ void CJabberProto::OmemoHandleMessage(HXML node, wchar_t *jid, time_t msgTime) if (dec_success <= 0) //TODO: check this... omemo xep have no info about tag
{
debugLogA("Jabber OMEMO: error: aes_128_gcm verification failed");
- return;
+ return true;
}
}
@@ -1855,6 +1853,7 @@ void CJabberProto::OmemoHandleMessage(HXML node, wchar_t *jid, time_t msgTime) recv.lParam = (LPARAM)((pFromResource != nullptr && m_bEnableRemoteControl) ? pFromResource->m_tszResourceName : 0);
ProtoChainRecvMsg(hContact, &recv);
mir_free(out);
+ return true;
}
void CJabberProto::OmemoHandleDeviceList(HXML node)
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index ab44f9f020..328192a811 100755 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -401,7 +401,7 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface //---- jabber_omemo.cpp --------------------------------------------------------------
- void OmemoHandleMessage(HXML node, wchar_t *jid, time_t msgTime);
+ bool OmemoHandleMessage(HXML node, wchar_t *jid, time_t msgTime);
void OmemoPutMessageToOutgoingQueue(MCONTACT hContact, int, const char* pszSrc);
void OmemoPutMessageToIncommingQueue(HXML node, const wchar_t *jid, time_t msgTime);
void OmemoHandleMessageQueue();
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index c274d62ed1..e75d3ec81f 100755 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -1321,7 +1321,8 @@ void CJabberProto::OnProcessMessage(HXML node, ThreadData *info) const wchar_t *jid = xmlGetAttrValue(node, L"from");
if (jid)
{
- OmemoHandleMessage(xNode, (wchar_t*)jid, msgTime);
+ if (!OmemoHandleMessage(xNode, (wchar_t*)jid, msgTime))
+ OmemoPutMessageToIncommingQueue(xNode, (wchar_t*)jid, msgTime);
continue;
}
}
|