diff options
author | Tobias Weimer <wishmaster51@googlemail.com> | 2016-01-25 21:20:35 +0000 |
---|---|---|
committer | Tobias Weimer <wishmaster51@googlemail.com> | 2016-01-25 21:20:35 +0000 |
commit | 80148955f82c205cc94f0112e0fbfe8f91bc4330 (patch) | |
tree | 252a0ae41cdb2ad3d798e311fb728b04e5bdbdbd /plugins/CryptoPP/src/cpp_pgpw.cpp | |
parent | a289103f2834d2219799f8d84e29a6d69c00574a (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_pgpw.cpp')
-rw-r--r-- | plugins/CryptoPP/src/cpp_pgpw.cpp | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/plugins/CryptoPP/src/cpp_pgpw.cpp b/plugins/CryptoPP/src/cpp_pgpw.cpp index 85de0513f0..366a3776de 100644 --- a/plugins/CryptoPP/src/cpp_pgpw.cpp +++ b/plugins/CryptoPP/src/cpp_pgpw.cpp @@ -135,27 +135,26 @@ LPSTR __cdecl pgp_get_error() LPSTR __cdecl pgp_encrypt(pCNTX ptr, LPCSTR szPlainMsg)
{
ptr->error = ERROR_NONE;
+ mir_free(ptr->tmp);
pPGPDATA p = (pPGPDATA)ptr->pdata;
- LPSTR szEncMsg;
- if (p->pgpKey)
- szEncMsg = p_pgp_encrypt_key(szPlainMsg, (LPCSTR)p->pgpKey);
- else
- szEncMsg = p_pgp_encrypt_keydb(szPlainMsg, p->pgpKeyID);
+ LPSTR szEncMsg = (p->pgpKey ? p_pgp_encrypt_key(szPlainMsg, (LPCSTR)p->pgpKey) : p_pgp_encrypt_keydb(szPlainMsg, p->pgpKeyID));
if (!szEncMsg) {
- replaceStr(ptr->tmp, NULL);
- return 0;
+ return ptr->tmp = 0;
}
+ else {
+ ptr->tmp = mir_strdup(szEncMsg);
+ LocalFree((LPVOID)szEncMsg);
- replaceStr(ptr->tmp, mir_strdup(szEncMsg));
- LocalFree((LPVOID)szEncMsg);
-
- return ptr->tmp;
+ return ptr->tmp;
+ }
}
LPSTR __cdecl pgp_decrypt(pCNTX ptr, LPCSTR szEncMsg)
{
ptr->error = ERROR_NONE;
+ mir_free(ptr->tmp);
+ ptr->tmp = NULL;
LPSTR szPlainMsg = p_pgp_decrypt_keydb(szEncMsg);
if (!szPlainMsg) {
@@ -166,12 +165,11 @@ LPSTR __cdecl pgp_decrypt(pCNTX ptr, LPCSTR szEncMsg) szPlainMsg = p_pgp_decrypt_key(szEncMsg, (LPCSTR)p->pgpKey);
}
if (!szPlainMsg) {
- replaceStr(ptr->tmp, NULL);
return NULL;
}
}
- replaceStr(ptr->tmp, mir_strdup(szPlainMsg));
+ ptr->tmp = mir_strdup(szPlainMsg);
LocalFree((LPVOID)szPlainMsg);
return ptr->tmp;
}
@@ -192,22 +190,21 @@ LPSTR __cdecl pgp_encode(HANDLE context, LPCSTR szPlainMsg) LPSTR __cdecl pgp_decode(HANDLE context, LPCSTR szEncMsg)
{
pCNTX ptr = get_context_on_id(context);
- if (!ptr) return NULL;
+ if (!ptr)
+ return NULL;
+ mir_free(ptr->tmp);
LPSTR szNewMsg = NULL;
LPSTR szOldMsg = pgp_decrypt(ptr, szEncMsg);
if (szOldMsg) {
if (!is_7bit_string(szOldMsg) && !is_utf8_string(szOldMsg)) {
- int slen = (int)strlen(szOldMsg) + 1;
- LPWSTR wszMsg = (LPWSTR)alloca(slen*sizeof(WCHAR));
- MultiByteToWideChar(CP_ACP, 0, szOldMsg, -1, wszMsg, slen*sizeof(WCHAR));
- szNewMsg = _strdup(utf8encode(wszMsg));
+ szNewMsg = mir_utf8encode(szOldMsg);
}
- else szNewMsg = _strdup(szOldMsg);
+ else
+ szNewMsg = mir_strdup(szOldMsg);
}
- replaceStr(ptr->tmp, szNewMsg);
- return szNewMsg;
+ return ptr->tmp = szNewMsg;
}
int __cdecl pgp_set_priv_key(LPCSTR LocalKey)
@@ -217,7 +214,9 @@ int __cdecl pgp_set_priv_key(LPCSTR LocalKey) int __cdecl pgp_set_key(HANDLE context, LPCSTR RemoteKey)
{
- pCNTX ptr = get_context_on_id(context); if (!ptr) return 0;
+ pCNTX ptr = get_context_on_id(context);
+ if (!ptr)
+ return 0;
pPGPDATA p = (pPGPDATA)cpp_alloc_pdata(ptr);
ptr->error = ERROR_NONE;
@@ -229,7 +228,9 @@ int __cdecl pgp_set_key(HANDLE context, LPCSTR RemoteKey) int __cdecl pgp_set_keyid(HANDLE context, PVOID RemoteKeyID)
{
- pCNTX ptr = get_context_on_id(context); if (!ptr) return 0;
+ pCNTX ptr = get_context_on_id(context);
+ if (!ptr)
+ return 0;
pPGPDATA p = (pPGPDATA)cpp_alloc_pdata(ptr);
ptr->error = ERROR_NONE;
|