Skip calling memset when the size is 0

memset(NULL, c, 0) has undefined behavior, so don't do it. clang-asan
complains.
This commit is contained in:
Gilles Peskine 2018-09-26 18:19:24 +02:00
parent 99ca35e968
commit f7ab5ad13a

View File

@ -1367,6 +1367,7 @@ void asymmetric_encryption_key_policy( int policy_usage,
else
TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED );
if( buffer_length != 0 )
memset( buffer, 0, buffer_length );
status = psa_asymmetric_decrypt( key_slot, exercise_alg,
buffer, buffer_length,
@ -2741,6 +2742,7 @@ void asymmetric_encrypt( int key_type_arg,
if( label->len == 0 )
{
output_length = ~0;
if( output_size != 0 )
memset( output, 0, output_size );
actual_status = psa_asymmetric_encrypt( slot, alg,
input_data->x, input_data->len,
@ -2882,6 +2884,7 @@ void asymmetric_decrypt( int key_type_arg,
if( label->len == 0 )
{
output_length = ~0;
if( output_size != 0 )
memset( output, 0, output_size );
TEST_ASSERT( psa_asymmetric_decrypt( slot, alg,
input_data->x, input_data->len,
@ -2949,6 +2952,7 @@ void asymmetric_decrypt_fail( int key_type_arg,
if( label->len == 0 )
{
output_length = ~0;
if( output_size != 0 )
memset( output, 0, output_size );
actual_status = psa_asymmetric_decrypt( slot, alg,
input_data->x, input_data->len,
@ -3332,6 +3336,7 @@ void generate_random( int bytes_arg )
* (2^(-8*number_of_runs)). */
for( run = 0; run < 10; run++ )
{
if( bytes != 0 )
memset( output, 0, bytes );
TEST_ASSERT( psa_generate_random( output, bytes ) == PSA_SUCCESS );