Skip to content
Snippets Groups Projects
Commit 44f0d4ea authored by Rafaël Carré's avatar Rafaël Carré
Browse files

malloc/free -> new[]/delete[]

parent fcc77198
No related branches found
No related tags found
No related merge requests found
...@@ -208,24 +208,20 @@ std::string AudioSrtpSession::getBase64ConcatenatedKeys() ...@@ -208,24 +208,20 @@ std::string AudioSrtpSession::getBase64ConcatenatedKeys()
void AudioSrtpSession::unBase64ConcatenatedKeys (std::string base64keys) void AudioSrtpSession::unBase64ConcatenatedKeys (std::string base64keys)
{ {
_remoteMasterKeyLength = sfl::CryptoSuites[_remoteCryptoSuite].masterKeyLength / 8; _remoteMasterKeyLength = sfl::CryptoSuites[_remoteCryptoSuite].masterKeyLength / 8;
_remoteMasterSaltLength = sfl::CryptoSuites[_remoteCryptoSuite].masterSaltLength / 8; _remoteMasterSaltLength = sfl::CryptoSuites[_remoteCryptoSuite].masterSaltLength / 8;
// length of decoded data data
int length;
// pointer to binary data // pointer to binary data
char *dataptr = (char*) base64keys.data(); char *dataptr = (char*) base64keys.data();
// decode concatenated binary keys // decode concatenated binary keys
char *output = decodeBase64 ( (unsigned char*) dataptr, strlen (dataptr), &length); char *output = decodeBase64 ( (unsigned char*) dataptr, strlen (dataptr));
// copy master and slt respectively // copy master and slt respectively
memcpy ( (void*) _remoteMasterKey, (void*) output, _remoteMasterKeyLength); memcpy ( (void*) _remoteMasterKey, (void*) output, _remoteMasterKeyLength);
memcpy ( (void*) _remoteMasterSalt, (void*) (output + _remoteMasterKeyLength), _remoteMasterSaltLength); memcpy ( (void*) _remoteMasterSalt, (void*) (output + _remoteMasterKeyLength), _remoteMasterSaltLength);
free (output); delete[] output;
} }
...@@ -317,13 +313,10 @@ std::string AudioSrtpSession::encodeBase64 (unsigned char *input, int length) ...@@ -317,13 +313,10 @@ std::string AudioSrtpSession::encodeBase64 (unsigned char *input, int length)
} }
#pragma GCC diagnostic warning "-Wunused-value" #pragma GCC diagnostic warning "-Wunused-value"
char* AudioSrtpSession::decodeBase64 (unsigned char *input, int length, int *length_out) char* AudioSrtpSession::decodeBase64 (unsigned char *input, int length)
{ {
BIO *b64, *bmem; BIO *b64, *bmem;
char *buffer = (char *) malloc (length);
memset (buffer, 0, length);
// init decoder and read-only BIO buffer // init decoder and read-only BIO buffer
b64 = BIO_new (BIO_f_base64()); b64 = BIO_new (BIO_f_base64());
BIO_set_flags (b64, BIO_FLAGS_BASE64_NO_NL); BIO_set_flags (b64, BIO_FLAGS_BASE64_NO_NL);
...@@ -334,12 +327,14 @@ char* AudioSrtpSession::decodeBase64 (unsigned char *input, int length, int *len ...@@ -334,12 +327,14 @@ char* AudioSrtpSession::decodeBase64 (unsigned char *input, int length, int *len
// create encoder chain // create encoder chain
bmem = BIO_push (b64, bmem); bmem = BIO_push (b64, bmem);
*length_out = BIO_read (bmem, buffer, length); char *buffer = new char[length];
memset (buffer, 0, length);
BIO_read (bmem, buffer, length);
BIO_free_all (bmem); BIO_free_all (bmem);
return buffer; return buffer;
} }
} }
...@@ -160,7 +160,7 @@ class AudioSrtpSession : public AudioRtpSession ...@@ -160,7 +160,7 @@ class AudioSrtpSession : public AudioRtpSession
/** /**
* Decode base64 data * Decode base64 data
*/ */
char* decodeBase64 (unsigned char *input, int length, int *length_out); char* decodeBase64 (unsigned char *input, int length);
/** Default local crypto suite is AES_CM_128_HMAC_SHA1_80*/ /** Default local crypto suite is AES_CM_128_HMAC_SHA1_80*/
int _localCryptoSuite; int _localCryptoSuite;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment