diff options
author | George Hazan <ghazan@miranda.im> | 2019-01-06 17:20:24 +0200 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-01-06 17:20:24 +0200 |
commit | 80ccccc6c8889ef287e78e0cf31a268ec2a39942 (patch) | |
tree | 620b6849e0ff2bd9ebf13aee551c0c1c944051a1 | |
parent | ac34a82d07d24856aee5629fec42ce9d0f33800d (diff) |
ICQ: crash fix
-rw-r--r-- | protocols/Icq10/src/server.cpp | 30 | ||||
-rw-r--r-- | src/mir_app/src/proto_utils.cpp | 40 |
2 files changed, 39 insertions, 31 deletions
diff --git a/protocols/Icq10/src/server.cpp b/protocols/Icq10/src/server.cpp index 835b0aac16..d67b2924a5 100644 --- a/protocols/Icq10/src/server.cpp +++ b/protocols/Icq10/src/server.cpp @@ -516,26 +516,32 @@ void CIcqProto::OnStartSession(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest*) void CIcqProto::OnReceiveAvatar(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq) { MCONTACT hContact = (MCONTACT)pReq->pUserInfo; + PROTO_AVATAR_INFORMATION ai = {}; + ai.hContact = hContact; + + if (pReply->resultCode != 200 || pReply->pData == nullptr) { +LBL_Error: + ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, HANDLE(&ai), 0); + return; + } const wchar_t *pwszExtension; - PROTO_AVATAR_INFORMATION ai; - ai.hContact = hContact; ai.format = ProtoGetBufferFormat(pReply->pData, &pwszExtension); setByte(hContact, "AvatarType", ai.format); GetAvatarFileName(hContact, ai.filename, _countof(ai.filename)); FILE *out = _wfopen(ai.filename, L"wb"); - if (out != nullptr) { - fwrite(pReply->pData, pReply->dataLength, 1, out); - fclose(out); - - if (hContact != 0) { - ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, HANDLE(&ai), 0); - debugLogW(L"Broadcast new avatar: %s", ai.filename); - } - else CallService(MS_AV_REPORTMYAVATARCHANGED, (WPARAM)m_szModuleName, 0); + if (out == nullptr) + goto LBL_Error; + + fwrite(pReply->pData, pReply->dataLength, 1, out); + fclose(out); + + if (hContact != 0) { + ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, HANDLE(&ai), 0); + debugLogW(L"Broadcast new avatar: %s", ai.filename); } - else ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, HANDLE(&ai), 0); + else CallService(MS_AV_REPORTMYAVATARCHANGED, (WPARAM)m_szModuleName, 0); } void CIcqProto::OnSearchResults(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq) diff --git a/src/mir_app/src/proto_utils.cpp b/src/mir_app/src/proto_utils.cpp index 666211e6ab..e1f3d803c3 100644 --- a/src/mir_app/src/proto_utils.cpp +++ b/src/mir_app/src/proto_utils.cpp @@ -320,29 +320,31 @@ MIR_APP_DLL(int) ProtoGetAvatarFormat(const wchar_t *ptszFileName) MIR_APP_DLL(int) ProtoGetBufferFormat(const void *pBuffer, const wchar_t **ptszExtension)
{
- if (!memcmp(pBuffer, "\x89PNG", 4)) {
- if (ptszExtension) *ptszExtension = L".png";
- return PA_FORMAT_PNG;
- }
+ if (pBuffer != nullptr) {
+ if (!memcmp(pBuffer, "\x89PNG", 4)) {
+ if (ptszExtension) *ptszExtension = L".png";
+ return PA_FORMAT_PNG;
+ }
- if (!memcmp(pBuffer, "GIF8", 4)) {
- if (ptszExtension) *ptszExtension = L".gif";
- return PA_FORMAT_GIF;
- }
+ if (!memcmp(pBuffer, "GIF8", 4)) {
+ if (ptszExtension) *ptszExtension = L".gif";
+ return PA_FORMAT_GIF;
+ }
- if (!memicmp(pBuffer, "<?xml", 5)) {
- if (ptszExtension) *ptszExtension = L".xml";
- return PA_FORMAT_XML;
- }
+ if (!memicmp(pBuffer, "<?xml", 5)) {
+ if (ptszExtension) *ptszExtension = L".xml";
+ return PA_FORMAT_XML;
+ }
- if (!memcmp(pBuffer, "\xFF\xD8\xFF\xE0", 4) || !memcmp(pBuffer, "\xFF\xD8\xFF\xE1", 4)) {
- if (ptszExtension) *ptszExtension = L".jpg";
- return PA_FORMAT_JPEG;
- }
+ if (!memcmp(pBuffer, "\xFF\xD8\xFF\xE0", 4) || !memcmp(pBuffer, "\xFF\xD8\xFF\xE1", 4)) {
+ if (ptszExtension) *ptszExtension = L".jpg";
+ return PA_FORMAT_JPEG;
+ }
- if (!memcmp(pBuffer, "BM", 2)) {
- if (ptszExtension) *ptszExtension = L".bmp";
- return PA_FORMAT_BMP;
+ if (!memcmp(pBuffer, "BM", 2)) {
+ if (ptszExtension) *ptszExtension = L".bmp";
+ return PA_FORMAT_BMP;
+ }
}
if (ptszExtension) *ptszExtension = L"";
|