mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-29 02:51:45 -04:00
added a new method rs_malloc that checks its arguments and prints a stacktrace on error/weird call. Changed the code everywhere to use this instead of malloc. Removed some mallocs and replaced with RsTemporaryMemory
This commit is contained in:
parent
9c6e7dfc13
commit
d13526facd
39 changed files with 274 additions and 132 deletions
|
@ -444,13 +444,10 @@ bool GxsSecurity::encrypt(uint8_t *& out, uint32_t &outlen, const uint8_t *in, u
|
|||
int out_offset = 0;
|
||||
|
||||
int max_evp_key_size = EVP_PKEY_size(public_key);
|
||||
ek = (unsigned char*)malloc(max_evp_key_size);
|
||||
ek = (unsigned char*)rs_safe_malloc(max_evp_key_size);
|
||||
|
||||
if(ek == NULL)
|
||||
{
|
||||
std::cerr << "(EE) memory allocation error for " << max_evp_key_size << " bytes in " << __PRETTY_FUNCTION__ << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
const EVP_CIPHER *cipher = EVP_aes_128_cbc();
|
||||
int cipher_block_size = EVP_CIPHER_block_size(cipher);
|
||||
|
@ -462,13 +459,10 @@ bool GxsSecurity::encrypt(uint8_t *& out, uint32_t &outlen, const uint8_t *in, u
|
|||
if(!EVP_SealInit(&ctx, EVP_aes_128_cbc(), &ek, &eklen, iv, &public_key, 1)) return false;
|
||||
|
||||
// now assign memory to out accounting for data, and cipher block size, key length, and key length val
|
||||
out = (uint8_t*)malloc(inlen + cipher_block_size + size_net_ekl + eklen + EVP_MAX_IV_LENGTH);
|
||||
out = (uint8_t*)rs_safe_malloc(inlen + cipher_block_size + size_net_ekl + eklen + EVP_MAX_IV_LENGTH);
|
||||
|
||||
if(out == NULL)
|
||||
{
|
||||
std::cerr << "gxssecurity::encrypt(): cnnot allocate memory of size " << inlen + cipher_block_size + size_net_ekl + eklen + EVP_MAX_IV_LENGTH << " to encrypt data." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
net_ekl = htonl(eklen);
|
||||
memcpy((unsigned char*)out + out_offset, &net_ekl, size_net_ekl);
|
||||
|
@ -547,13 +541,11 @@ bool GxsSecurity::decrypt(uint8_t *& out, uint32_t & outlen, const uint8_t *in,
|
|||
|
||||
EVP_CIPHER_CTX ctx;
|
||||
int eklen = 0, net_ekl = 0;
|
||||
unsigned char *ek = (unsigned char*)malloc(EVP_PKEY_size(privateKey));
|
||||
unsigned char *ek = (unsigned char*)rs_safe_malloc(EVP_PKEY_size(privateKey));
|
||||
|
||||
if(ek == NULL)
|
||||
{
|
||||
std::cerr << "Memory allocation error in " << __PRETTY_FUNCTION__ << " for " << EVP_PKEY_size(privateKey) << " bytes." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
unsigned char iv[EVP_MAX_IV_LENGTH];
|
||||
EVP_CIPHER_CTX_init(&ctx);
|
||||
|
||||
|
@ -587,13 +579,10 @@ bool GxsSecurity::decrypt(uint8_t *& out, uint32_t & outlen, const uint8_t *in,
|
|||
std::cerr << "Severe error in " << __PRETTY_FUNCTION__ << ": cannot encrypt. " << std::endl;
|
||||
return false ;
|
||||
}
|
||||
out = (uint8_t*)malloc(inlen - in_offset);
|
||||
out = (uint8_t*)rs_safe_malloc(inlen - in_offset);
|
||||
|
||||
if(out == NULL)
|
||||
{
|
||||
std::cerr << "gxssecurity::decrypt(): cannot allocate memory of size " << inlen - in_offset << " to decrypt data." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!EVP_OpenUpdate(&ctx, (unsigned char*) out, &out_currOffset, (unsigned char*)in + in_offset, inlen - in_offset))
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue