PKCS7: In EncodeEncryptedData, free the attribs and flattenedAttribs if

they were allocated, not based on if they should be allocated.
This commit is contained in:
John Safranek 2020-10-24 12:41:10 -07:00
parent e24ac4211d
commit 3f5620089e
No known key found for this signature in database
GPG Key ID: 8CE817DE0D3CCB4A

View File

@ -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);