From 55837fa25428d4a6f379ba4824f411bd5e604dc0 Mon Sep 17 00:00:00 2001 From: Eric Blankenhorn Date: Tue, 4 Jun 2024 12:37:46 -0500 Subject: [PATCH] Static analysis fixes --- src/internal.c | 62 +++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/src/internal.c b/src/internal.c index 439139889..4991982a1 100644 --- a/src/internal.c +++ b/src/internal.c @@ -7043,7 +7043,7 @@ void FreeHandshakeHashes(WOLFSSL* ssl) int InitHandshakeHashesAndCopy(WOLFSSL* ssl, HS_Hashes* source, HS_Hashes** destination) { - int ret = 0; + int ret; HS_Hashes* tmpHashes; if (source == NULL) @@ -7053,7 +7053,11 @@ int InitHandshakeHashesAndCopy(WOLFSSL* ssl, HS_Hashes* source, tmpHashes = ssl->hsHashes; ssl->hsHashes = NULL; - InitHandshakeHashes(ssl); + ret = InitHandshakeHashes(ssl); + if (ret != 0) { + WOLFSSL_MSG_EX("InitHandshakeHashes failed. err = %d", ret); + return ret; + } *destination = ssl->hsHashes; ssl->hsHashes = tmpHashes; @@ -7061,50 +7065,50 @@ int InitHandshakeHashesAndCopy(WOLFSSL* ssl, HS_Hashes* source, /* now copy the source contents to the destination */ #ifndef NO_OLD_TLS #ifndef NO_SHA - ret = wc_ShaCopy(&source->hashSha, &(*destination)->hashSha); + ret = wc_ShaCopy(&source->hashSha, &(*destination)->hashSha); #endif #ifndef NO_MD5 - if (ret == 0) - ret = wc_Md5Copy(&source->hashMd5, &(*destination)->hashMd5); + if (ret == 0) + ret = wc_Md5Copy(&source->hashMd5, &(*destination)->hashMd5); #endif #endif /* !NO_OLD_TLS */ #ifndef NO_SHA256 - if (ret == 0) - ret = wc_Sha256Copy(&source->hashSha256, - &(*destination)->hashSha256); + if (ret == 0) + ret = wc_Sha256Copy(&source->hashSha256, + &(*destination)->hashSha256); #endif #ifdef WOLFSSL_SHA384 - if (ret == 0) - ret = wc_Sha384Copy(&source->hashSha384, - &(*destination)->hashSha384); + if (ret == 0) + ret = wc_Sha384Copy(&source->hashSha384, + &(*destination)->hashSha384); #endif #ifdef WOLFSSL_SHA512 - if (ret == 0) - ret = wc_Sha512Copy(&source->hashSha512, - &(*destination)->hashSha512); + if (ret == 0) + ret = wc_Sha512Copy(&source->hashSha512, + &(*destination)->hashSha512); #endif #ifdef WOLFSSL_SM3 - if (ret == 0) - ret = wc_Sm3Copy(&source->hashSm3, - &(*destination)->hashSm3); + if (ret == 0) + ret = wc_Sm3Copy(&source->hashSm3, + &(*destination)->hashSm3); #endif #if (defined(HAVE_ED25519) || defined(HAVE_ED448) || \ (defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3))) && \ !defined(WOLFSSL_NO_CLIENT_AUTH) - if (ret == 0 && source->messages != NULL) { - (*destination)->messages = (byte*)XMALLOC(source->length, ssl->heap, - DYNAMIC_TYPE_HASHES); - (*destination)->length = source->length; - (*destination)->prevLen = source->prevLen; + if (ret == 0 && source->messages != NULL) { + (*destination)->messages = (byte*)XMALLOC(source->length, ssl->heap, + DYNAMIC_TYPE_HASHES); + (*destination)->length = source->length; + (*destination)->prevLen = source->prevLen; - if ((*destination)->messages == NULL) { - ret = MEMORY_E; - } - else { - XMEMCPY((*destination)->messages, source->messages, - source->length); - } + if ((*destination)->messages == NULL) { + ret = MEMORY_E; } + else { + XMEMCPY((*destination)->messages, source->messages, + source->length); + } + } #endif return ret;