Make allocation of reassembly bitmap optional
This commit adds a parameter to ssl_prepare_reassembly_buffer()
allowing to disable the allocation of space for a reassembly bitmap.
This will allow this function to be used for the allocation of buffers
for future handshake messages in case these need no fragmentation.
@@ -3473,6 +3473,7 @@ static int ssl_bitmask_check( unsigned char *mask, size_t len )
/* msg_len does not include the handshake header */
static int ssl_prepare_reassembly_buffer( mbedtls_ssl_context *ssl, /* debug */
unsigned msg_len,
+ unsigned add_bitmap,
unsigned char **target )
{
size_t alloc_len;
@@ -3490,6 +3491,8 @@ static int ssl_prepare_reassembly_buffer( mbedtls_ssl_context *ssl, /* debug */
alloc_len = 12; /* Handshake header */
alloc_len += msg_len; /* Content buffer */
+
+ if( add_bitmap )
alloc_len += msg_len / 8 + ( msg_len % 8 != 0 ); /* Bitmap */
buf = mbedtls_calloc( 1, alloc_len );
@@ -3528,7 +3531,8 @@ static int ssl_reassemble_dtls_handshake( mbedtls_ssl_context *ssl )
*/
if( ssl->handshake->hs_msg == NULL )
{
- ret = ssl_prepare_reassembly_buffer( msg_len, &ssl->handshake->hs_msg );
+ ret = ssl_prepare_reassembly_buffer( msg_len, 1,
+ &ssl->handshake->hs_msg );
if( ret != 0 )
return( ret );
