From 3f5620089e1ec96cb6053ecf98677de745fa8798 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Sat, 24 Oct 2020 12:41:10 -0700 Subject: [PATCH] PKCS7: In EncodeEncryptedData, free the attribs and flattenedAttribs if they were allocated, not based on if they should be allocated. --- wolfcrypt/src/pkcs7.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/wolfcrypt/src/pkcs7.c b/wolfcrypt/src/pkcs7.c index e9ae9c64e..3d0941f5a 100644 --- a/wolfcrypt/src/pkcs7.c +++ b/wolfcrypt/src/pkcs7.c @@ -11751,10 +11751,10 @@ int wc_PKCS7_EncodeEncryptedData(PKCS7* pkcs7, byte* output, word32 outputSz) if (totalSz > (int)outputSz) { WOLFSSL_MSG("PKCS#7 output buffer too small"); - if (pkcs7->unprotectedAttribsSz != 0) { + if (attribs != NULL) XFREE(attribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + if (flatAttribs != NULL) XFREE(flatAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - } XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7); XFREE(plain, pkcs7->heap, DYNAMIC_TYPE_PKCS7); return BUFFER_E; @@ -11790,10 +11790,12 @@ int wc_PKCS7_EncodeEncryptedData(PKCS7* pkcs7, byte* output, word32 outputSz) idx += attribsSetSz; XMEMCPY(output + idx, flatAttribs, attribsSz); idx += attribsSz; - XFREE(attribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - XFREE(flatAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); } + if (attribs != NULL) + XFREE(attribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + if (flatAttribs != NULL) + XFREE(flatAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7); XFREE(plain, pkcs7->heap, DYNAMIC_TYPE_PKCS7);