From 51f2bcb40c86fa514ae44349e743337d50da4fd5 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Wed, 3 Nov 2021 13:27:29 +0000 Subject: Some cleanup in X509_REQ_get_extensions(3), no functional change. 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 | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'lib/libcrypto') diff --git a/lib/libcrypto/x509/x509_req.c b/lib/libcrypto/x509/x509_req.c index cbf731cc5a0..e7f871449f8 100644 --- a/lib/libcrypto/x509/x509_req.c +++ b/lib/libcrypto/x509/x509_req.c @@ -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); } /* -- cgit v1.2.3