Skip to content

Commit

Permalink
Fix possible memleak in PKCS7_add0_attrib_signing_time
Browse files Browse the repository at this point in the history
When PKCS7_add_signed_attribute fails, the ASN1_TIME
object may be leaked when it was not passed in as
input parameter.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from #22772)

(cherry picked from commit 7d52539)
(cherry picked from commit e83a231)
  • Loading branch information
bernd-edlinger authored and levitte committed Nov 22, 2023
1 parent 9288932 commit 1ef5200
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crypto/pkcs7/pk7_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,18 @@ int PKCS7_add_attrib_content_type(PKCS7_SIGNER_INFO *si, ASN1_OBJECT *coid)

int PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t)
{
if (t == NULL && (t = X509_gmtime_adj(NULL, 0)) == NULL) {
ASN1_TIME *tmp = NULL;

if (t == NULL && (tmp = t = X509_gmtime_adj(NULL, 0)) == NULL) {
ERR_raise(ERR_LIB_PKCS7, ERR_R_MALLOC_FAILURE);
return 0;
}
return PKCS7_add_signed_attribute(si, NID_pkcs9_signingTime,
V_ASN1_UTCTIME, t);
if (!PKCS7_add_signed_attribute(si, NID_pkcs9_signingTime,
V_ASN1_UTCTIME, t)) {
ASN1_TIME_free(tmp);
return 0;
}
return 1;
}

int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si,
Expand Down

0 comments on commit 1ef5200

Please sign in to comment.