Fix the build of sample programs without mbedtls_strerror

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2021-08-06 14:37:01 +02:00
parent 2729878046
commit 680747b868
3 changed files with 16 additions and 6 deletions

View File

@ -0,0 +1,3 @@
Bugfix
* Fix the build of sample programs when neither MBEDTLS_ERROR_C nor
MBEDTLS_ERROR_STRERROR_DUMMY is enabled.

View File

@ -202,7 +202,9 @@ int main( int argc, char *argv[] )
{
int ret = 1;
int exit_code = MBEDTLS_EXIT_FAILURE;
char buf[1024];
#if defined(MBEDTLS_ERROR_C)
char buf[200];
#endif
int i;
char *p, *q;
@ -220,7 +222,9 @@ int main( int argc, char *argv[] )
mbedtls_ctr_drbg_init( &ctr_drbg );
mbedtls_pk_init( &key );
#if defined(MBEDTLS_ERROR_C)
memset( buf, 0, sizeof( buf ) );
#endif
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P ); mbedtls_mpi_init( &Q );
mbedtls_mpi_init( &D ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &DP );
@ -316,8 +320,7 @@ int main( int argc, char *argv[] )
mbedtls_ctr_drbg_random, &ctr_drbg );
if( ret != 0 )
{
mbedtls_strerror( ret, (char *) buf, sizeof(buf) );
mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile returned -0x%04x - %s\n\n", (unsigned int) -ret, buf );
mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile returned -0x%04x", (unsigned int) -ret );
goto exit;
}
@ -377,8 +380,7 @@ int main( int argc, char *argv[] )
if( ret != 0 )
{
mbedtls_strerror( ret, (char *) buf, sizeof(buf) );
mbedtls_printf( " failed\n ! mbedtls_pk_parse_public_key returned -0x%04x - %s\n\n", (unsigned int) -ret, buf );
mbedtls_printf( " failed\n ! mbedtls_pk_parse_public_key returned -0x%04x", (unsigned int) -ret );
goto exit;
}

View File

@ -105,7 +105,6 @@ int read_certificates( const char *const *filenames )
mbedtls_x509_crt cas;
int ret = 0;
const char *const *cur;
char error_message[200];
mbedtls_x509_crt_init( &cas );
@ -114,9 +113,15 @@ int read_certificates( const char *const *filenames )
ret = mbedtls_x509_crt_parse_file( &cas, *cur );
if( ret != 0 )
{
#if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
char error_message[200];
mbedtls_strerror( ret, error_message, sizeof( error_message ) );
printf( "\n%s: -0x%04x (%s)\n",
*cur, (unsigned) -ret, error_message );
#else
printf( "\n%s: -0x%04x\n",
*cur, (unsigned) -ret );
#endif
goto exit;
}
}