]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
x_attrib.c: Fix print_hex() function
authorTomas Mraz <tomas@openssl.org>
Mon, 1 Jul 2024 07:52:53 +0000 (09:52 +0200)
committerMatt Caswell <matt@openssl.org>
Fri, 12 Jul 2024 10:20:35 +0000 (11:20 +0100)
- 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 <shane.lontis@oracle.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24771)

crypto/x509/x_attrib.c

index 5446e0c2fe57fef4903471bea8f1d02363255a9c..a5d1a04e1dd97b402237903c54fee6541bb638f1 100644 (file)
@@ -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) {