@@ -7043,7 +7043,7 @@ void FreeHandshakeHashes(WOLFSSL* ssl)
70437043int InitHandshakeHashesAndCopy(WOLFSSL* ssl, HS_Hashes* source,
70447044 HS_Hashes** destination)
70457045{
7046- int ret = 0 ;
7046+ int ret;
70477047 HS_Hashes* tmpHashes;
70487048
70497049 if (source == NULL)
@@ -7053,58 +7053,62 @@ int InitHandshakeHashesAndCopy(WOLFSSL* ssl, HS_Hashes* source,
70537053 tmpHashes = ssl->hsHashes;
70547054 ssl->hsHashes = NULL;
70557055
7056- InitHandshakeHashes(ssl);
7056+ ret = InitHandshakeHashes(ssl);
7057+ if (ret != 0) {
7058+ WOLFSSL_MSG_EX("InitHandshakeHashes failed. err = %d", ret);
7059+ return ret;
7060+ }
70577061
70587062 *destination = ssl->hsHashes;
70597063 ssl->hsHashes = tmpHashes;
70607064
70617065 /* now copy the source contents to the destination */
70627066#ifndef NO_OLD_TLS
70637067 #ifndef NO_SHA
7064- ret = wc_ShaCopy(&source->hashSha, &(*destination)->hashSha);
7068+ ret = wc_ShaCopy(&source->hashSha, &(*destination)->hashSha);
70657069 #endif
70667070 #ifndef NO_MD5
7067- if (ret == 0)
7068- ret = wc_Md5Copy(&source->hashMd5, &(*destination)->hashMd5);
7071+ if (ret == 0)
7072+ ret = wc_Md5Copy(&source->hashMd5, &(*destination)->hashMd5);
70697073 #endif
70707074 #endif /* !NO_OLD_TLS */
70717075 #ifndef NO_SHA256
7072- if (ret == 0)
7073- ret = wc_Sha256Copy(&source->hashSha256,
7074- &(*destination)->hashSha256);
7076+ if (ret == 0)
7077+ ret = wc_Sha256Copy(&source->hashSha256,
7078+ &(*destination)->hashSha256);
70757079 #endif
70767080 #ifdef WOLFSSL_SHA384
7077- if (ret == 0)
7078- ret = wc_Sha384Copy(&source->hashSha384,
7079- &(*destination)->hashSha384);
7081+ if (ret == 0)
7082+ ret = wc_Sha384Copy(&source->hashSha384,
7083+ &(*destination)->hashSha384);
70807084 #endif
70817085 #ifdef WOLFSSL_SHA512
7082- if (ret == 0)
7083- ret = wc_Sha512Copy(&source->hashSha512,
7084- &(*destination)->hashSha512);
7086+ if (ret == 0)
7087+ ret = wc_Sha512Copy(&source->hashSha512,
7088+ &(*destination)->hashSha512);
70857089 #endif
70867090 #ifdef WOLFSSL_SM3
7087- if (ret == 0)
7088- ret = wc_Sm3Copy(&source->hashSm3,
7089- &(*destination)->hashSm3);
7091+ if (ret == 0)
7092+ ret = wc_Sm3Copy(&source->hashSm3,
7093+ &(*destination)->hashSm3);
70907094 #endif
70917095 #if (defined(HAVE_ED25519) || defined(HAVE_ED448) || \
70927096 (defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3))) && \
70937097 !defined(WOLFSSL_NO_CLIENT_AUTH)
7094- if (ret == 0 && source->messages != NULL) {
7095- (*destination)->messages = (byte*)XMALLOC(source->length, ssl->heap,
7096- DYNAMIC_TYPE_HASHES);
7097- (*destination)->length = source->length;
7098- (*destination)->prevLen = source->prevLen;
7098+ if (ret == 0 && source->messages != NULL) {
7099+ (*destination)->messages = (byte*)XMALLOC(source->length, ssl->heap,
7100+ DYNAMIC_TYPE_HASHES);
7101+ (*destination)->length = source->length;
7102+ (*destination)->prevLen = source->prevLen;
70997103
7100- if ((*destination)->messages == NULL) {
7101- ret = MEMORY_E;
7102- }
7103- else {
7104- XMEMCPY((*destination)->messages, source->messages,
7105- source->length);
7106- }
7104+ if ((*destination)->messages == NULL) {
7105+ ret = MEMORY_E;
71077106 }
7107+ else {
7108+ XMEMCPY((*destination)->messages, source->messages,
7109+ source->length);
7110+ }
7111+ }
71087112 #endif
71097113
71107114 return ret;
0 commit comments