Added missing free() in error handling code (Patch rom G10H4ck)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7819 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-01-05 19:26:50 +00:00
parent a29a8c8a49
commit 306d6852c2

View File

@ -462,9 +462,8 @@ bool GxsSecurity::decrypt(uint8_t *& out, int & outlen, const uint8_t *in, int i
EVP_CIPHER_CTX ctx; EVP_CIPHER_CTX ctx;
int eklen = 0, net_ekl = 0; int eklen = 0, net_ekl = 0;
unsigned char *ek = NULL; unsigned char *ek = (unsigned char*)malloc(EVP_PKEY_size(privateKey));
unsigned char iv[EVP_MAX_IV_LENGTH]; unsigned char iv[EVP_MAX_IV_LENGTH];
ek = (unsigned char*)malloc(EVP_PKEY_size(privateKey));
EVP_CIPHER_CTX_init(&ctx); EVP_CIPHER_CTX_init(&ctx);
int in_offset = 0, out_currOffset = 0; int in_offset = 0, out_currOffset = 0;
@ -474,13 +473,13 @@ bool GxsSecurity::decrypt(uint8_t *& out, int & outlen, const uint8_t *in, int i
eklen = ntohl(net_ekl); eklen = ntohl(net_ekl);
in_offset += size_net_ekl; in_offset += size_net_ekl;
// Conservative limits to detect weird errors due to corrupted encoding. // Conservative limits to detect weird errors due to corrupted encoding.
// if(eklen < 0 || eklen > 512 || eklen+in_offset > inlen)
if(eklen < 0 || eklen > 512 || eklen+in_offset > inlen) {
{ std::cerr << "Error while deserialising encryption key length: eklen = " << std::dec << eklen << ". Giving up decryption." << std::endl;
std::cerr << "Error while deserialising encryption key length: eklen = " << std::dec << eklen << ". Giving up decryption." << std::endl; free(ek);
return false ; return false;
} }
memcpy(ek, (unsigned char*)in + in_offset, eklen); memcpy(ek, (unsigned char*)in + in_offset, eklen);
in_offset += eklen; in_offset += eklen;
@ -506,7 +505,6 @@ bool GxsSecurity::decrypt(uint8_t *& out, int & outlen, const uint8_t *in, int i
return false; return false;
} }
in_offset += out_currOffset;
outlen += out_currOffset; outlen += out_currOffset;
if(!EVP_OpenFinal(&ctx, (unsigned char*)out + out_currOffset, &out_currOffset)) if(!EVP_OpenFinal(&ctx, (unsigned char*)out + out_currOffset, &out_currOffset))