Skip to content

Commit

Permalink
Don't call memcpy(NULL, 0) which has undefined behavior
Browse files Browse the repository at this point in the history
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
  • Loading branch information
gilles-peskine-arm committed Jun 29, 2022
1 parent 96b8d31 commit d97de55
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/suites/test_suite_asn1write.function
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,12 @@ void test_asn1_write_bitstrings( data_t *bitstring, int bits,

#if defined(MBEDTLS_ASN1_PARSE_C)
ASSERT_ALLOC( masked_bitstring, byte_length );
memcpy( masked_bitstring, bitstring->x, byte_length );
if( bits % 8 != 0 )
masked_bitstring[byte_length - 1] &= ~( 0xff >> ( bits % 8 ) );
if( byte_length != 0 )
{
memcpy( masked_bitstring, bitstring->x, byte_length );
if( bits % 8 != 0 )
masked_bitstring[byte_length - 1] &= ~( 0xff >> ( bits % 8 ) );
}
size_t value_bits = bits;
if( is_named )
{
Expand Down

0 comments on commit d97de55

Please sign in to comment.