From: Tomas Mraz Date: Mon, 1 Jul 2024 07:52:53 +0000 (+0200) Subject: x_attrib.c: Fix print_hex() function X-Git-Tag: openssl-3.4.0-alpha1~351 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b24a8200ab3e135c84dbf1054b92ffb713a7b5ad;p=thirdparty%2Fopenssl.git x_attrib.c: Fix print_hex() function - Better handle 0 length input - Use OPENSSL_buf2hexstr() instead of OPENSSL_buf2hexstr_ex() which fixes insufficient length of the allocate buffer. Reviewed-by: Shane Lontis Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/24771) --- diff --git a/crypto/x509/x_attrib.c b/crypto/x509/x_attrib.c index 5446e0c2fe5..a5d1a04e1dd 100644 --- a/crypto/x509/x_attrib.c +++ b/crypto/x509/x_attrib.c @@ -60,25 +60,19 @@ X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value) static int print_hex(BIO *out, unsigned char *buf, int len) { - int result = -1; + int result = 1; char *hexbuf; - int hexlen = len * 2 + 1; - hexbuf = OPENSSL_malloc(hexlen); + if (len == 0) + return 1; + + hexbuf = OPENSSL_buf2hexstr(buf, len); if (hexbuf == NULL) return 0; - result = OPENSSL_buf2hexstr_ex(hexbuf, hexlen, NULL, buf, len, ':'); - if (result != 1) - goto err; - if ((result = BIO_puts(out, hexbuf)) <= 0) - goto err; + result = BIO_puts(out, hexbuf) > 0; OPENSSL_free(hexbuf); - return 1; - - err: - OPENSSL_free(hexbuf); - return 0; + return result; } static int print_oid(BIO *out, const ASN1_OBJECT *oid) {