Skip to content

Commit

Permalink
Fix potential memory leak in save_statusInfo()
Browse files Browse the repository at this point in the history
If sk_ASN1_UTF8STRING_push() fails then the duplicated string will leak
memory. Add a ASN1_UTF8STRING_free() to fix this.

CLA: trivial

Reviewed-by: Tom Cosgrove <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#25604)
  • Loading branch information
nielsdos authored and t8m committed Oct 7, 2024
1 parent d8b7a6e commit 0a2a8d9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crypto/cmp/cmp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ static int save_statusInfo(OSSL_CMP_CTX *ctx, OSSL_CMP_PKISI *si)
ss = si->statusString; /* may be NULL */
for (i = 0; i < sk_ASN1_UTF8STRING_num(ss); i++) {
ASN1_UTF8STRING *str = sk_ASN1_UTF8STRING_value(ss, i);
ASN1_UTF8STRING *dup = ASN1_STRING_dup(str);

if (!sk_ASN1_UTF8STRING_push(ctx->statusString, ASN1_STRING_dup(str)))
if (dup == NULL || !sk_ASN1_UTF8STRING_push(ctx->statusString, dup)) {
ASN1_UTF8STRING_free(dup);
return 0;
}
}
return 1;
}
Expand Down

0 comments on commit 0a2a8d9

Please sign in to comment.