From 8435c381bd8940617157e1db6499003de4a72ee4 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Mon, 5 Jun 2017 15:02:46 +0100 Subject: [PATCH] Remove use of size zero array in ECJPAKE test suite The ECJPAKE test suite uses a size zero array for the empty password used in the tests, which is not valid C. This commit fixes this. This originally showed up as a compilation failure on Visual Studio 2015, documented in IOTSSL-1242, but can also be observed with GCC when using the -Wpedantic compilation option. --- tests/suites/test_suite_ecjpake.function | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/suites/test_suite_ecjpake.function b/tests/suites/test_suite_ecjpake.function index 11cf8dc94..5c8856b16 100644 --- a/tests/suites/test_suite_ecjpake.function +++ b/tests/suites/test_suite_ecjpake.function @@ -109,7 +109,10 @@ void ecjpake_selftest() void read_round_one( int role, char *data, int ref_ret ) { mbedtls_ecjpake_context ctx; - const unsigned char pw[] = {}; + + const unsigned char * pw = NULL; + const size_t pw_len = 0; + unsigned char *msg; size_t len; @@ -119,7 +122,7 @@ void read_round_one( int role, char *data, int ref_ret ) TEST_ASSERT( msg != NULL ); TEST_ASSERT( mbedtls_ecjpake_setup( &ctx, role, - MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, 0 ) == 0 ); + MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, pw_len ) == 0 ); TEST_ASSERT( mbedtls_ecjpake_read_round_one( &ctx, msg, len ) == ref_ret ); @@ -133,7 +136,10 @@ exit: void read_round_two_cli( char *data, int ref_ret ) { mbedtls_ecjpake_context ctx; - const unsigned char pw[] = {}; + + const unsigned char * pw = NULL; + const size_t pw_len = 0; + unsigned char *msg; size_t len; @@ -143,7 +149,7 @@ void read_round_two_cli( char *data, int ref_ret ) TEST_ASSERT( msg != NULL ); TEST_ASSERT( mbedtls_ecjpake_setup( &ctx, MBEDTLS_ECJPAKE_CLIENT, - MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, 0 ) == 0 ); + MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, pw_len ) == 0 ); TEST_ASSERT( ecjpake_test_load( &ctx, ADD_SIZE( ecjpake_test_x1 ), ADD_SIZE( ecjpake_test_x2 ), @@ -163,7 +169,10 @@ exit: void read_round_two_srv( char *data, int ref_ret ) { mbedtls_ecjpake_context ctx; - const unsigned char pw[] = {}; + + const unsigned char * pw = NULL; + const size_t pw_len = 0; + unsigned char *msg; size_t len; @@ -173,7 +182,7 @@ void read_round_two_srv( char *data, int ref_ret ) TEST_ASSERT( msg != NULL ); TEST_ASSERT( mbedtls_ecjpake_setup( &ctx, MBEDTLS_ECJPAKE_SERVER, - MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, 0 ) == 0 ); + MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, pw_len ) == 0 ); TEST_ASSERT( ecjpake_test_load( &ctx, ADD_SIZE( ecjpake_test_x3 ), ADD_SIZE( ecjpake_test_x4 ),