From 4d325effb6ac409e36b04657860e81fb3df760f3 Mon Sep 17 00:00:00 2001 From: Sergey Bolhovskoy Date: Wed, 21 Jan 2015 04:48:55 +0000 Subject: VKontakte: fix potential crash on sent files (detect by coverity) fix memory leak (detect by coverity) git-svn-id: http://svn.miranda-ng.org/main/trunk@11885 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/vk_feed.cpp | 10 ++++++++-- protocols/VKontakte/src/vk_files.cpp | 18 ++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'protocols') diff --git a/protocols/VKontakte/src/vk_feed.cpp b/protocols/VKontakte/src/vk_feed.cpp index 4744a9e44b..18a8286a16 100644 --- a/protocols/VKontakte/src/vk_feed.cpp +++ b/protocols/VKontakte/src/vk_feed.cpp @@ -358,12 +358,16 @@ CVKNewsItem* CVkProto::GetVkParent(JSONNODE *pParent, VKObjType vkParentType, TC ClearFormatNick(tszText); JSONNODE *pNode = json_get(pParent, "photo"); - if (pNode) + if (pNode){ + delete vkNotificationItem; return GetVkParent(pNode, vkPhoto, tszText.IsEmpty() ? NULL : tszText.GetBuffer()); + } pNode = json_get(pParent, "video"); - if (pNode) + if (pNode){ + delete vkNotificationItem; return GetVkParent(pNode, vkVideo, tszText.IsEmpty() ? NULL : tszText.GetBuffer()); + } LONG iId = json_as_int(json_get(pParent, "id")); @@ -371,6 +375,7 @@ CVKNewsItem* CVkProto::GetVkParent(JSONNODE *pParent, VKObjType vkParentType, TC if (pNode) { CMString tszRepl; tszRepl.AppendFormat(_T("?reply=%d"), iId); + delete vkNotificationItem; return GetVkParent(pNode, vkPost, tszText.IsEmpty() ? NULL : tszText.GetBuffer(), tszRepl.GetBuffer()); } @@ -378,6 +383,7 @@ CVKNewsItem* CVkProto::GetVkParent(JSONNODE *pParent, VKObjType vkParentType, TC if (pNode) { CMString tszRepl; tszRepl.AppendFormat(_T("?reply=%d"), iId); + delete vkNotificationItem; return GetVkParent(pNode, vkTopic, tszText.IsEmpty() ? NULL : tszText.GetBuffer(), tszRepl.GetBuffer()); } } diff --git a/protocols/VKontakte/src/vk_files.cpp b/protocols/VKontakte/src/vk_files.cpp index 79e5edc400..9679d3e9b4 100644 --- a/protocols/VKontakte/src/vk_files.cpp +++ b/protocols/VKontakte/src/vk_files.cpp @@ -187,7 +187,12 @@ void CVkProto::OnReciveUploadServer(NETLIBHTTPREQUEST *reply, AsyncHttpRequest * } fseek(pFile, 0, SEEK_END); - size_t szFileLen = ftell(pFile); //FileSize + long iFileLen = ftell(pFile); //FileSize + if (iFileLen < 1) { + fclose(pFile); + SendFileFiled(fup, _T("ErrorReadFile")); + return; + } fseek(pFile, 0, SEEK_SET); AsyncHttpRequest *pUploadReq = new AsyncHttpRequest(this, REQUEST_POST, uri.GetBuffer(), false, &CVkProto::OnReciveUpload); @@ -218,17 +223,22 @@ void CVkProto::OnReciveUploadServer(NETLIBHTTPREQUEST *reply, AsyncHttpRequest * DataEnd += boundary; DataEnd += "--\r\n"; // Body size - size_t dataLength = szFileLen + DataBegin.GetLength() + DataEnd.GetLength(); + long dataLength = iFileLen + DataBegin.GetLength() + DataEnd.GetLength(); // Body { char* pData = (char *)mir_alloc(dataLength); memcpy(pData, (void *)DataBegin.GetBuffer(), DataBegin.GetLength()); pUploadReq->pData = pData; pData += DataBegin.GetLength(); - fread(pData, 1, szFileLen, pFile); + size_t szBytes = fread(pData, 1, iFileLen, pFile); fclose(pFile); - pData += szFileLen; + if (szBytes != iFileLen) { + SendFileFiled(fup, _T("ErrorReadFile")); + return; + } + + pData += iFileLen; memcpy(pData, (void *)DataEnd.GetBuffer(), DataEnd.GetLength()); // } Body -- cgit v1.2.3