From c24b187a8815c9b50094cd93e6b392b472534a5b Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Fri, 8 Mar 2024 01:54:37 +0700 Subject: [PATCH] fixes for clang-tidy warnings --- wolfcrypt/src/pkcs7.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/wolfcrypt/src/pkcs7.c b/wolfcrypt/src/pkcs7.c index 9e418963b..780a97f0c 100644 --- a/wolfcrypt/src/pkcs7.c +++ b/wolfcrypt/src/pkcs7.c @@ -2537,6 +2537,9 @@ static int wc_PKCS7_EncodeContentStream(PKCS7* pkcs7, ESD* esd, void* aes, if (cipherType == WC_CIPHER_NONE && esd && esd->contentDigestSet != 1) { /* calculate hash for content */ ret = wc_HashInit(&esd->hash, esd->hashType); + if (ret != 0) { + return ret; + } } encContentOut = XMALLOC(BER_OCTET_LENGTH + MAX_OCTET_STR_SZ, @@ -2596,6 +2599,11 @@ static int wc_PKCS7_EncodeContentStream(PKCS7* pkcs7, ESD* esd, void* aes, ret = wc_PKCS7_EncodeContentStreamHelper(pkcs7, cipherType, aes, encContentOut, contentData, BER_OCTET_LENGTH, out, &outIdx, esd); + if (ret != 0) { + XFREE(encContentOut, heap, DYNAMIC_TYPE_PKCS7); + XFREE(contentData, heap, DYNAMIC_TYPE_PKCS7); + return ret; + } /* copy over any remaining data */ XMEMCPY(contentData, buf + sz, contentDataRead); @@ -2628,11 +2636,13 @@ static int wc_PKCS7_EncodeContentStream(PKCS7* pkcs7, ESD* esd, void* aes, /* encrypt and flush out remainder of content data */ ret = wc_PKCS7_EncodeContentStreamHelper(pkcs7, cipherType, aes, encContentOut, contentData, idx, out, &outIdx, esd); - - if (cipherType == WC_CIPHER_NONE && esd && esd->contentDigestSet != 1) { - ret = wc_HashFinal(&esd->hash, esd->hashType, - esd->contentDigest + 2); - wc_HashFree(&esd->hash, esd->hashType); + if (ret == 0) { + if (cipherType == WC_CIPHER_NONE && esd && + esd->contentDigestSet != 1) { + ret = wc_HashFinal(&esd->hash, esd->hashType, + esd->contentDigest + 2); + wc_HashFree(&esd->hash, esd->hashType); + } } XFREE(encContentOut, heap, DYNAMIC_TYPE_PKCS7);