summaryrefslogtreecommitdiff
path: root/plugins/CryptoPP/src/cpp_svcs.cpp
diff options
context:
space:
mode:
authorTobias Weimer <wishmaster51@googlemail.com>2016-01-25 21:20:35 +0000
committerTobias Weimer <wishmaster51@googlemail.com>2016-01-25 21:20:35 +0000
commit80148955f82c205cc94f0112e0fbfe8f91bc4330 (patch)
tree252a0ae41cdb2ad3d798e311fb728b04e5bdbdbd /plugins/CryptoPP/src/cpp_svcs.cpp
parenta289103f2834d2219799f8d84e29a6d69c00574a (diff)
Crypto++: Fix for many memory leaks introduced in [6593].
Note that replaceStr already does mir_strdup the argument! git-svn-id: http://svn.miranda-ng.org/main/trunk@16168 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/CryptoPP/src/cpp_svcs.cpp')
-rw-r--r--plugins/CryptoPP/src/cpp_svcs.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/plugins/CryptoPP/src/cpp_svcs.cpp b/plugins/CryptoPP/src/cpp_svcs.cpp
index 01b95bc2d9..ed5af8bdbb 100644
--- a/plugins/CryptoPP/src/cpp_svcs.cpp
+++ b/plugins/CryptoPP/src/cpp_svcs.cpp
@@ -48,10 +48,14 @@ LPSTR __cdecl cpp_encrypt(pCNTX ptr, LPCSTR szPlainMsg)
ciphered.insert(0, (LPSTR)&dataflag, 1);
clen = (unsigned)ciphered.length();
+ mir_free(ptr->tmp);
if (ptr->features & FEATURES_BASE64)
- replaceStr(ptr->tmp, mir_base64_encode((PBYTE)ciphered.data(), clen));
- else
- replaceStr(ptr->tmp, base16encode(ciphered.data(), clen));
+ ptr->tmp = mir_base64_encode((PBYTE)ciphered.data(), clen);
+ else {
+ char *base16 = base16encode(ciphered.data(), clen);
+ ptr->tmp = mir_strdup(base16);
+ free(base16);
+ }
return ptr->tmp;
}
@@ -116,13 +120,16 @@ LPSTR __cdecl cpp_decrypt(pCNTX ptr, LPCSTR szEncMsg)
cbcDecryptor.Put((PBYTE)bciphered, clen);
cbcDecryptor.MessageEnd();
+ mir_free(ptr->tmp);
+
if (dataflag & DATA_GZIP) {
size_t clen2 = clen;
LPSTR res = (LPSTR)cpp_gunzip((PBYTE)unciphered.data(), unciphered.length(), clen2);
- replaceStr(ptr->tmp, mir_strndup(res, clen2));
+ ptr->tmp = mir_strndup(res, clen2);
free(res);
}
- else replaceStr(ptr->tmp, mir_strdup(unciphered.c_str()));
+ else
+ ptr->tmp = mir_strdup(unciphered.c_str());
ptr->error = ERROR_NONE;
return ptr->tmp;
@@ -249,15 +256,17 @@ LPSTR __cdecl cpp_decode(HANDLE context, LPCSTR szEncMsg)
memcpy(szNewMsg + slen, wstring, slen*sizeof(WCHAR));
}
}
- replaceStr(ptr->tmp, szNewMsg);
- return szNewMsg;
+ mir_free(ptr->tmp);
+ return ptr->tmp = szNewMsg;
}
// decode message return UTF8z
LPSTR __cdecl cpp_decodeU(HANDLE context, LPCSTR szEncMsg)
{
pCNTX ptr = get_context_on_id(context);
- if (!ptr) return NULL;
+ if (!ptr)
+ return NULL;
+ mir_free(ptr->tmp);
cpp_alloc_pdata(ptr); pSIMDATA p = (pSIMDATA)ptr->pdata;
if (!p->KeyX) { ptr->error = ERROR_NO_KEYX; return NULL; }
@@ -277,8 +286,7 @@ LPSTR __cdecl cpp_decodeU(HANDLE context, LPCSTR szEncMsg)
szNewMsg = mir_strdup(utf8encode(wstring));
}
}
- replaceStr(ptr->tmp, szNewMsg);
- return szNewMsg;
+ return ptr->tmp = szNewMsg;
}
int __cdecl cpp_encrypt_file(HANDLE context, LPCSTR file_in, LPCSTR file_out)