Some cleanup in X509_REQ_get_extensions(3), no functional change.
authorschwarze <schwarze@openbsd.org>
Wed, 3 Nov 2021 13:27:28 +0000 (13:27 +0000)
committerschwarze <schwarze@openbsd.org>
Wed, 3 Nov 2021 13:27:28 +0000 (13:27 +0000)
In this function, merge everything that is worth merging
from the OpenSSL 1.1.1 branch, which is still under a free license,
mostly the relevant part of commit 9b0a4531 Mar 14 23:48:47 2015 +0000
to use X509_ATTRIBUTE_get0_type(3) rather than re-implementing it.

While here,
* use d2i_X509_EXTENSIONS(3) rather than ASN1_item_d2i(3);
* test pointers explicitly against NULL, not with '!', as suggested by tb@;
* drop some useless parentheses as suggested by tb@.

OK tb@

lib/libcrypto/x509/x509_req.c

index cbf731c..e7f8714 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: x509_req.c,v 1.25 2021/11/03 12:53:25 schwarze Exp $ */
+/* $OpenBSD: x509_req.c,v 1.26 2021/11/03 13:27:28 schwarze Exp $ */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -212,24 +212,20 @@ X509_REQ_get_extensions(X509_REQ *req)
        int idx, *pnid;
        const unsigned char *p;
 
-       if ((req == NULL) || (req->req_info == NULL) || !ext_nids)
-               return (NULL);
+       if (req == NULL || req->req_info == NULL || ext_nids == NULL)
+               return NULL;
        for (pnid = ext_nids; *pnid != NID_undef; pnid++) {
                idx = X509_REQ_get_attr_by_NID(req, *pnid, -1);
                if (idx == -1)
                        continue;
                attr = X509_REQ_get_attr(req, idx);
-               if (attr->single)
-                       ext = attr->value.single;
-               else if (sk_ASN1_TYPE_num(attr->value.set))
-                       ext = sk_ASN1_TYPE_value(attr->value.set, 0);
+               ext = X509_ATTRIBUTE_get0_type(attr, 0);
                break;
        }
-       if (!ext || (ext->type != V_ASN1_SEQUENCE))
+       if (ext == NULL || ext->type != V_ASN1_SEQUENCE)
                return NULL;
        p = ext->value.sequence->data;
-       return (STACK_OF(X509_EXTENSION) *)ASN1_item_d2i(NULL, &p,
-           ext->value.sequence->length, &X509_EXTENSIONS_it);
+       return d2i_X509_EXTENSIONS(NULL, &p, ext->value.sequence->length);
 }
 
 /*