diff options
author | Sergey Bolhovskoy <elzorfox@ya.ru> | 2015-01-21 04:48:55 +0000 |
---|---|---|
committer | Sergey Bolhovskoy <elzorfox@ya.ru> | 2015-01-21 04:48:55 +0000 |
commit | 4d325effb6ac409e36b04657860e81fb3df760f3 (patch) | |
tree | 49f72194c53f2443d8dbb298e74ddcc6abba66ee /protocols/VKontakte/src/vk_files.cpp | |
parent | 7d4e48d8de0eb5ed44dc7f11a1f777ea461a2843 (diff) |
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
Diffstat (limited to 'protocols/VKontakte/src/vk_files.cpp')
-rw-r--r-- | protocols/VKontakte/src/vk_files.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
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
|