summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2021-11-05 17:08:12 +0000
committertb <>2021-11-05 17:08:12 +0000
commit7f11ef3d087b85d9ef80b28d47e8ce3d7382cacf (patch)
tree5c69ffa0b0b51049b73f204e9f5e57ee2588c86d /src/lib
parent333b908cb213f668dae7181d2c389929c1ec077c (diff)
downloadopenbsd-7f11ef3d087b85d9ef80b28d47e8ce3d7382cacf.tar.gz
openbsd-7f11ef3d087b85d9ef80b28d47e8ce3d7382cacf.tar.bz2
openbsd-7f11ef3d087b85d9ef80b28d47e8ce3d7382cacf.zip
Use calloc() to remove the need of silly zeroing of most members.
Check for allocation failures and if one happens push an error on the stack and clean up using X509_STORE_free(). ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/x509/x509_lu.c46
1 files changed, 18 insertions, 28 deletions
diff --git a/src/lib/libcrypto/x509/x509_lu.c b/src/lib/libcrypto/x509/x509_lu.c
index b968a13d6f..3fa572c7ef 100644
--- a/src/lib/libcrypto/x509/x509_lu.c
+++ b/src/lib/libcrypto/x509/x509_lu.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_lu.c,v 1.41 2021/11/05 17:06:42 tb Exp $ */ 1/* $OpenBSD: x509_lu.c,v 1.42 2021/11/05 17:08:12 tb 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 *
@@ -186,40 +186,30 @@ x509_object_cmp(const X509_OBJECT * const *a, const X509_OBJECT * const *b)
186X509_STORE * 186X509_STORE *
187X509_STORE_new(void) 187X509_STORE_new(void)
188{ 188{
189 X509_STORE *ret; 189 X509_STORE *store;
190 190
191 if ((ret = malloc(sizeof(X509_STORE))) == NULL) 191 if ((store = calloc(1, sizeof(*store))) == NULL)
192 return NULL; 192 goto err;
193 ret->objs = sk_X509_OBJECT_new(x509_object_cmp);
194 ret->cache = 1;
195 ret->get_cert_methods = sk_X509_LOOKUP_new_null();
196 ret->verify = 0;
197 ret->verify_cb = 0;
198 193
199 if ((ret->param = X509_VERIFY_PARAM_new()) == NULL) 194 if ((store->objs = sk_X509_OBJECT_new(x509_object_cmp)) == NULL)
195 goto err;
196 if ((store->get_cert_methods = sk_X509_LOOKUP_new_null()) == NULL)
197 goto err;
198 if ((store->param = X509_VERIFY_PARAM_new()) == NULL)
200 goto err; 199 goto err;
201 200
202 ret->get_issuer = 0; 201 if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, store,
203 ret->check_issued = 0; 202 &store->ex_data))
204 ret->check_revocation = 0;
205 ret->get_crl = 0;
206 ret->check_crl = 0;
207 ret->cert_crl = 0;
208 ret->lookup_certs = 0;
209 ret->lookup_crls = 0;
210 ret->cleanup = 0;
211
212 if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data))
213 goto err; 203 goto err;
214 204
215 ret->references = 1; 205 store->references = 1;
216 return ret; 206
207 return store;
208
209 err:
210 X509error(ERR_R_MALLOC_FAILURE);
211 X509_STORE_free(store);
217 212
218err:
219 X509_VERIFY_PARAM_free(ret->param);
220 sk_X509_LOOKUP_free(ret->get_cert_methods);
221 sk_X509_OBJECT_free(ret->objs);
222 free(ret);
223 return NULL; 213 return NULL;
224} 214}
225 215