summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorschwarze <>2021-11-03 12:53:25 +0000
committerschwarze <>2021-11-03 12:53:25 +0000
commitddc0ed504e881d30d4c140ae756f549f24d696da (patch)
tree9ed5cc149555082f1d5267d6caee226499c3178b /src
parent76e9f577da320593c54eb46e4ae17bbf74fec42b (diff)
downloadopenbsd-ddc0ed504e881d30d4c140ae756f549f24d696da.tar.gz
openbsd-ddc0ed504e881d30d4c140ae756f549f24d696da.tar.bz2
openbsd-ddc0ed504e881d30d4c140ae756f549f24d696da.zip
Fix two bugs in X509_REQ_add_extensions_nid(3)
that i noticed while documneting the function: * missing return value check for ASN1_item_i2d(3) and * missing return value check for OBJ_nid2obj(3). In the function X509_REQ_add_extensions_nid(3), merge everything that is worth merging from the OpenSSL 1.1.1 branch, which is still under a free license; that's mostly parts of the commit 9b0a4531 Mar 14 23:48:47 2015 +0000 (containing the bugfix, even though the OpenSSL commit message did not mention the bugs) and some minor stylistic changes from 0f113f3e and 26a7d938. While here, use i2d_X509_EXTENSIONS(3) instead of the layer-violating call to ASN1_item_i2d(3), and include a few stylistic tweaks from tb@. OK tb@, and jsing@ agreed on the general direction.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/x509/x509_req.c45
1 files changed, 13 insertions, 32 deletions
diff --git a/src/lib/libcrypto/x509/x509_req.c b/src/lib/libcrypto/x509/x509_req.c
index 556e32b317..cbf731cc5a 100644
--- a/src/lib/libcrypto/x509/x509_req.c
+++ b/src/lib/libcrypto/x509/x509_req.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_req.c,v 1.24 2021/11/01 20:53:08 tb Exp $ */ 1/* $OpenBSD: x509_req.c,v 1.25 2021/11/03 12:53:25 schwarze Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -232,46 +232,27 @@ X509_REQ_get_extensions(X509_REQ *req)
232 ext->value.sequence->length, &X509_EXTENSIONS_it); 232 ext->value.sequence->length, &X509_EXTENSIONS_it);
233} 233}
234 234
235/* Add a STACK_OF extensions to a certificate request: allow alternative OIDs 235/*
236 * in case we want to create a non standard one. 236 * Add a STACK_OF extensions to a certificate request: allow alternative OIDs
237 * in case we want to create a non-standard one.
237 */ 238 */
238 239
239int 240int
240X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts, 241X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
241 int nid) 242 int nid)
242{ 243{
243 ASN1_TYPE *at = NULL; 244 unsigned char *ext = NULL;
244 X509_ATTRIBUTE *attr = NULL; 245 int extlen;
246 int rv;
245 247
246 if (!(at = ASN1_TYPE_new()) || 248 extlen = i2d_X509_EXTENSIONS(exts, &ext);
247 !(at->value.sequence = ASN1_STRING_new())) 249 if (extlen <= 0)
248 goto err; 250 return 0;
249 251
250 at->type = V_ASN1_SEQUENCE; 252 rv = X509_REQ_add1_attr_by_NID(req, nid, V_ASN1_SEQUENCE, ext, extlen);
251 /* Generate encoding of extensions */ 253 free(ext);
252 at->value.sequence->length = ASN1_item_i2d((ASN1_VALUE *)exts,
253 &at->value.sequence->data, &X509_EXTENSIONS_it);
254 if (!(attr = X509_ATTRIBUTE_new()))
255 goto err;
256 if (!(attr->value.set = sk_ASN1_TYPE_new_null()))
257 goto err;
258 if (!sk_ASN1_TYPE_push(attr->value.set, at))
259 goto err;
260 at = NULL;
261 attr->single = 0;
262 attr->object = OBJ_nid2obj(nid);
263 if (!req->req_info->attributes) {
264 if (!(req->req_info->attributes = sk_X509_ATTRIBUTE_new_null()))
265 goto err;
266 }
267 if (!sk_X509_ATTRIBUTE_push(req->req_info->attributes, attr))
268 goto err;
269 return 1;
270 254
271err: 255 return rv;
272 X509_ATTRIBUTE_free(attr);
273 ASN1_TYPE_free(at);
274 return 0;
275} 256}
276 257
277/* This is the normal usage: use the "official" OID */ 258/* This is the normal usage: use the "official" OID */