From cf9ab63863468621ef742c7eef7fb6e7d08c806f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 27 Aug 2015 22:03:33 +0200 Subject: [PATCH] Fix error reporting in pkey/pk_* programs --- programs/pkey/pk_decrypt.c | 7 +++++-- programs/pkey/pk_encrypt.c | 7 +++++-- programs/pkey/pk_sign.c | 7 +++++-- programs/pkey/pk_verify.c | 7 +++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/programs/pkey/pk_decrypt.c b/programs/pkey/pk_decrypt.c index bcfb2c690..2ccbf3b9e 100644 --- a/programs/pkey/pk_decrypt.c +++ b/programs/pkey/pk_decrypt.c @@ -151,8 +151,11 @@ exit: mbedtls_entropy_free( &entropy ); #if defined(MBEDTLS_ERROR_C) - mbedtls_strerror( ret, (char *) buf, sizeof(buf) ); - mbedtls_printf( " ! Last error was: %s\n", buf ); + if( ret != 0 ) + { + mbedtls_strerror( ret, (char *) buf, sizeof(buf) ); + mbedtls_printf( " ! Last error was: %s\n", buf ); + } #endif #if defined(_WIN32) diff --git a/programs/pkey/pk_encrypt.c b/programs/pkey/pk_encrypt.c index 300cb77fa..fe84aee77 100644 --- a/programs/pkey/pk_encrypt.c +++ b/programs/pkey/pk_encrypt.c @@ -151,8 +151,11 @@ exit: mbedtls_entropy_free( &entropy ); #if defined(MBEDTLS_ERROR_C) - mbedtls_strerror( ret, (char *) buf, sizeof(buf) ); - mbedtls_printf( " ! Last error was: %s\n", buf ); + if( ret != 0 ) + { + mbedtls_strerror( ret, (char *) buf, sizeof(buf) ); + mbedtls_printf( " ! Last error was: %s\n", buf ); + } #endif #if defined(_WIN32) diff --git a/programs/pkey/pk_sign.c b/programs/pkey/pk_sign.c index 82be0cf0c..ce2520975 100644 --- a/programs/pkey/pk_sign.c +++ b/programs/pkey/pk_sign.c @@ -156,8 +156,11 @@ exit: mbedtls_entropy_free( &entropy ); #if defined(MBEDTLS_ERROR_C) - mbedtls_strerror( ret, (char *) buf, sizeof(buf) ); - mbedtls_printf( " ! Last error was: %s\n", buf ); + if( ret != 0 ) + { + mbedtls_strerror( ret, (char *) buf, sizeof(buf) ); + mbedtls_printf( " ! Last error was: %s\n", buf ); + } #endif #if defined(_WIN32) diff --git a/programs/pkey/pk_verify.c b/programs/pkey/pk_verify.c index a6d490149..a1a2389aa 100644 --- a/programs/pkey/pk_verify.c +++ b/programs/pkey/pk_verify.c @@ -132,8 +132,11 @@ exit: mbedtls_pk_free( &pk ); #if defined(MBEDTLS_ERROR_C) - mbedtls_strerror( ret, (char *) buf, sizeof(buf) ); - mbedtls_printf( " ! Last error was: %s\n", buf ); + if( ret != 0 ) + { + mbedtls_strerror( ret, (char *) buf, sizeof(buf) ); + mbedtls_printf( " ! Last error was: %s\n", buf ); + } #endif #if defined(_WIN32)