diff --git a/tests/suites/test_suite_pkwrite.function b/tests/suites/test_suite_pkwrite.function index cbe1c1c1e..1c98bd143 100644 --- a/tests/suites/test_suite_pkwrite.function +++ b/tests/suites/test_suite_pkwrite.function @@ -25,16 +25,16 @@ void pk_write_pubkey_check( char *key_file ) mbedtls_pk_init( &key ); TEST_ASSERT( mbedtls_pk_parse_public_keyfile( &key, key_file ) == 0 ); - ret = mbedtls_pk_write_pubkey_pem( &key, buf, sizeof( buf ) - 1); - TEST_ASSERT( ret >= 0 ); + ret = mbedtls_pk_write_pubkey_pem( &key, buf, sizeof( buf )); + TEST_ASSERT( ret == 0 ); f = fopen( key_file, "r" ); TEST_ASSERT( f != NULL ); - ilen = fread( check_buf, 1, sizeof( check_buf ) - 1, f ); + ilen = fread( check_buf, 1, sizeof( check_buf ), f ); fclose( f ); TEST_ASSERT( ilen == strlen( (char *) buf ) ); - TEST_ASSERT( strncmp( (char *) buf, (char *) check_buf, sizeof( buf ) ) == 0 ); + TEST_ASSERT( memcmp( (char *) buf, (char *) check_buf, ilen ) == 0 ); exit: mbedtls_pk_free( &key ); @@ -57,16 +57,16 @@ void pk_write_key_check( char *key_file ) mbedtls_pk_init( &key ); TEST_ASSERT( mbedtls_pk_parse_keyfile( &key, key_file, NULL ) == 0 ); - ret = mbedtls_pk_write_key_pem( &key, buf, sizeof( buf ) - 1); + ret = mbedtls_pk_write_key_pem( &key, buf, sizeof( buf )); TEST_ASSERT( ret >= 0 ); f = fopen( key_file, "r" ); TEST_ASSERT( f != NULL ); - ilen = fread( check_buf, 1, sizeof( check_buf ) - 1, f ); + ilen = fread( check_buf, 1, sizeof( check_buf ), f ); fclose( f ); TEST_ASSERT( ilen == strlen( (char *) buf ) ); - TEST_ASSERT( strncmp( (char *) buf, (char *) check_buf, sizeof( buf ) ) == 0 ); + TEST_ASSERT( memcmp( (char *) buf, (char *) check_buf, ilen ) == 0 ); exit: mbedtls_pk_free( &key );