From 7edad280360df0c85d0d38c0d31074111c26e8fc Mon Sep 17 00:00:00 2001 From: Benjamin Kier Date: Thu, 30 May 2019 14:49:17 -0400 Subject: [PATCH 1/2] Fixed possibly undefined variable warnings by initializing variables to 0. --- library/entropy.c | 2 +- library/hmac_drbg.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/entropy.c b/library/entropy.c index f8db1a550..ac7e9051f 100644 --- a/library/entropy.c +++ b/library/entropy.c @@ -258,7 +258,7 @@ int mbedtls_entropy_update_manual( mbedtls_entropy_context *ctx, */ static int entropy_gather_internal( mbedtls_entropy_context *ctx ) { - int ret, i, have_one_strong = 0; + int ret = 0, i, have_one_strong = 0; unsigned char buf[MBEDTLS_ENTROPY_MAX_GATHER]; size_t olen; diff --git a/library/hmac_drbg.c b/library/hmac_drbg.c index 50d88bd54..edecc6e12 100644 --- a/library/hmac_drbg.c +++ b/library/hmac_drbg.c @@ -74,7 +74,7 @@ int mbedtls_hmac_drbg_update_ret( mbedtls_hmac_drbg_context *ctx, unsigned char rounds = ( additional != NULL && add_len != 0 ) ? 2 : 1; unsigned char sep[1]; unsigned char K[MBEDTLS_MD_MAX_SIZE]; - int ret; + int ret = 0; for( sep[0] = 0; sep[0] < rounds; sep[0]++ ) { From 006c1b5f4e8dd2da632ddd5df97f1b5ec9163734 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Mon, 30 Sep 2019 17:29:54 +0200 Subject: [PATCH 2/2] Prefer initializing ret to error values These initial values shouldn't be used, but in case they accidentally get used after a code change, fail safe. --- library/entropy.c | 4 +++- library/hmac_drbg.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/library/entropy.c b/library/entropy.c index ac7e9051f..d7091cbf7 100644 --- a/library/entropy.c +++ b/library/entropy.c @@ -258,7 +258,9 @@ int mbedtls_entropy_update_manual( mbedtls_entropy_context *ctx, */ static int entropy_gather_internal( mbedtls_entropy_context *ctx ) { - int ret = 0, i, have_one_strong = 0; + int ret = MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; + int i; + int have_one_strong = 0; unsigned char buf[MBEDTLS_ENTROPY_MAX_GATHER]; size_t olen; diff --git a/library/hmac_drbg.c b/library/hmac_drbg.c index edecc6e12..67123dfd2 100644 --- a/library/hmac_drbg.c +++ b/library/hmac_drbg.c @@ -74,7 +74,7 @@ int mbedtls_hmac_drbg_update_ret( mbedtls_hmac_drbg_context *ctx, unsigned char rounds = ( additional != NULL && add_len != 0 ) ? 2 : 1; unsigned char sep[1]; unsigned char K[MBEDTLS_MD_MAX_SIZE]; - int ret = 0; + int ret = MBEDTLS_ERR_MD_BAD_INPUT_DATA; for( sep[0] = 0; sep[0] < rounds; sep[0]++ ) {