git: 4ce723fb2550 - main - uefisign: use ASN1_STRING_set0() instead of ASN1_STRING_set()

From: Gordon Tetlow <gordon_at_FreeBSD.org>
Date: Mon, 16 Nov 2026 04:39:26 UTC
The branch main has been updated by gordon:

URL: https://cgit.FreeBSD.org/src/commit/?id=4ce723fb2550241970a58491b969ac3a7ac7127b

commit 4ce723fb2550241970a58491b969ac3a7ac7127b
Author:     Gordon Tetlow <gordon@FreeBSD.org>
AuthorDate: 2026-11-08 03:50:44 +0000
Commit:     Gordon Tetlow <gordon@FreeBSD.org>
CommitDate: 2026-11-16 04:38:33 +0000

    uefisign: use ASN1_STRING_set0() instead of ASN1_STRING_set()
    
    Prepare for future OpenSSL API changes.
    
    OpenSSL 4.1 deprecates ASN1_STRING_set. Move to ASN1_STRING_set0 which
    requires the DER buffer to be allocated with OPENSSL_zalloc so ownership
    can be assumed by the string.
    
    Reviewed by:            imp
    Differential Revision:  https://reviews.freebsd.org/D61532
---
 usr.sbin/uefisign/uefisign.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/usr.sbin/uefisign/uefisign.c b/usr.sbin/uefisign/uefisign.c
index bf6a2c0d0e42..942bf1851f45 100644
--- a/usr.sbin/uefisign/uefisign.c
+++ b/usr.sbin/uefisign/uefisign.c
@@ -204,9 +204,9 @@ magic(PKCS7 *pkcs7, const char *digest, size_t digest_len)
 	 * the actual signing.
 	 */
 	len = i2d_ASN1_TYPE(t, NULL);
-	tmp = buf = calloc(1, len);
+	tmp = buf = OPENSSL_zalloc(len);
 	if (tmp == NULL)
-		err(1, "calloc");
+		err(1, "OPENSSL_zalloc");
 	i2d_ASN1_TYPE(t, &tmp);
 
 	/*
@@ -231,7 +231,8 @@ magic(PKCS7 *pkcs7, const char *digest, size_t digest_len)
 
 	t = ASN1_TYPE_new();
 	s = ASN1_STRING_new();
-	ASN1_STRING_set(s, buf, len);
+	/* s takes ownership of buf. */
+	ASN1_STRING_set0(s, buf, len);
 	ASN1_TYPE_set(t, V_ASN1_SEQUENCE, s);
 
 	PKCS7_set0_type_other(pkcs7->d.sign->contents, nid, t);