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