Skip to content

Commit

Permalink
CMS_ContentInfo_free(): fix mem leak on encrypted content key
Browse files Browse the repository at this point in the history
Fixes #21026

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from #21058)

(cherry picked from commit 7a18574)
  • Loading branch information
DDvO committed Jun 1, 2023
1 parent 4b4819d commit e66e952
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crypto/cms/cms_env.c
Expand Up @@ -142,10 +142,12 @@ CMS_EncryptedContentInfo *ossl_cms_get0_env_enc_content(const CMS_ContentInfo *c
{
switch (cms_get_enveloped_type(cms)) {
case CMS_ENVELOPED_STANDARD:
return cms->d.envelopedData->encryptedContentInfo;
return cms->d.envelopedData == NULL ? NULL
: cms->d.envelopedData->encryptedContentInfo;

case CMS_ENVELOPED_AUTH:
return cms->d.authEnvelopedData->authEncryptedContentInfo;
return cms->d.authEnvelopedData == NULL ? NULL
: cms->d.authEnvelopedData->authEncryptedContentInfo;

default:
return NULL;
Expand Down
4 changes: 4 additions & 0 deletions crypto/cms/cms_lib.c
Expand Up @@ -76,6 +76,10 @@ CMS_ContentInfo *CMS_ContentInfo_new(void)
void CMS_ContentInfo_free(CMS_ContentInfo *cms)
{
if (cms != NULL) {
CMS_EncryptedContentInfo *ec = ossl_cms_get0_env_enc_content(cms);

if (ec != NULL)
OPENSSL_clear_free(ec->key, ec->keylen);
OPENSSL_free(cms->ctx.propq);
ASN1_item_free((ASN1_VALUE *)cms, ASN1_ITEM_rptr(CMS_ContentInfo));
}
Expand Down

0 comments on commit e66e952

Please sign in to comment.