mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-01-27 06:35:22 +00:00
Prevent unsafe memcpy
Some tests cause a zero length input or output, which can mean the allocated test output buffers can be zero length. Protect against calling memcpy blindly in these situations. Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
parent
d4e99ed40c
commit
ac3c20013c
@ -3292,7 +3292,10 @@ void aead_multipart_encrypt( int key_type_arg, data_t *key_data,
|
||||
part_length, part_data,
|
||||
part_data_size, &output_part_length ) );
|
||||
|
||||
memcpy( ( output_data + part_offset ), part_data, output_part_length );
|
||||
if( output_data && output_part_length )
|
||||
{
|
||||
memcpy( ( output_data + part_offset ), part_data, output_part_length );
|
||||
}
|
||||
|
||||
part_offset += part_length;
|
||||
output_length += output_part_length;
|
||||
@ -3312,13 +3315,19 @@ void aead_multipart_encrypt( int key_type_arg, data_t *key_data,
|
||||
tag_buffer, tag_length,
|
||||
&tag_size ) );
|
||||
|
||||
memcpy( ( output_data + output_length ), final_data, output_part_length );
|
||||
if( output_data && output_part_length )
|
||||
{
|
||||
memcpy( ( output_data + output_length ), final_data, output_part_length );
|
||||
}
|
||||
|
||||
TEST_EQUAL(tag_length, tag_size);
|
||||
|
||||
output_length += output_part_length;
|
||||
|
||||
memcpy( ( output_data + output_length ), tag_buffer, tag_length );
|
||||
if( output_data && tag_length )
|
||||
{
|
||||
memcpy( ( output_data + output_length ), tag_buffer, tag_length );
|
||||
}
|
||||
|
||||
output_length += tag_length;
|
||||
|
||||
@ -3516,7 +3525,10 @@ void aead_multipart_encrypt_decrypt( int key_type_arg, data_t *key_data,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
memcpy( ( output_data + part_offset ), part_data, output_part_length );
|
||||
if( output_data && output_part_length )
|
||||
{
|
||||
memcpy( ( output_data + part_offset ), part_data, output_part_length );
|
||||
}
|
||||
|
||||
part_offset += part_length;
|
||||
output_length += output_part_length;
|
||||
@ -3547,7 +3559,10 @@ void aead_multipart_encrypt_decrypt( int key_type_arg, data_t *key_data,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
memcpy( ( output_data + output_length ), final_data, output_part_length );
|
||||
if( output_data &&output_part_length )
|
||||
{
|
||||
memcpy( ( output_data + output_length ), final_data, output_part_length );
|
||||
}
|
||||
|
||||
output_length += output_part_length;
|
||||
|
||||
@ -3666,7 +3681,10 @@ void aead_multipart_encrypt_decrypt( int key_type_arg, data_t *key_data,
|
||||
part_length, part_data,
|
||||
part_data_size, &output_part_length ) );
|
||||
|
||||
memcpy( ( output_data2 + part_offset ), part_data, output_part_length );
|
||||
if( output_data2 && output_part_length )
|
||||
{
|
||||
memcpy( ( output_data2 + part_offset ), part_data, output_part_length );
|
||||
}
|
||||
|
||||
part_offset += part_length;
|
||||
output_length2 += output_part_length;
|
||||
@ -3684,7 +3702,10 @@ void aead_multipart_encrypt_decrypt( int key_type_arg, data_t *key_data,
|
||||
&output_part_length,
|
||||
tag_buffer, tag_length ) );
|
||||
|
||||
memcpy( ( output_data2 + output_length2 ), final_data, output_part_length);
|
||||
if( output_data2 && output_part_length )
|
||||
{
|
||||
memcpy( ( output_data2 + output_length2 ), final_data, output_part_length);
|
||||
}
|
||||
|
||||
output_length2 += output_part_length;
|
||||
|
||||
@ -3872,7 +3893,10 @@ void aead_multipart_decrypt( int key_type_arg, data_t *key_data,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
memcpy( ( output_data + part_offset ), part_data, output_part_length );
|
||||
if( output_data && output_part_length )
|
||||
{
|
||||
memcpy( ( output_data + part_offset ), part_data, output_part_length );
|
||||
}
|
||||
|
||||
part_offset += part_length;
|
||||
output_length += output_part_length;
|
||||
@ -3903,7 +3927,10 @@ void aead_multipart_decrypt( int key_type_arg, data_t *key_data,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
memcpy( ( output_data + output_length ), final_data, output_part_length );
|
||||
if( output_data && output_part_length )
|
||||
{
|
||||
memcpy( ( output_data + output_length ), final_data, output_part_length );
|
||||
}
|
||||
|
||||
output_length += output_part_length;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user