summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2021-11-05 17:08:13 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2021-11-05 17:08:13 +0000
commite5e55b3e4dcd73ae5133c66c9c01eb7ec9bdb6bc (patch)
treefbd8544aa6d7b65106c26a77de722415a01f974a
parent351479614304a71aab34a82654c0ce169c4411c7 (diff)
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
-rw-r--r--lib/libcrypto/x509/x509_lu.c46
1 files changed, 18 insertions, 28 deletions
diff --git a/lib/libcrypto/x509/x509_lu.c b/lib/libcrypto/x509/x509_lu.c
index b968a13d6f0..3fa572c7efa 100644
--- a/lib/libcrypto/x509/x509_lu.c
+++ b/lib/libcrypto/x509/x509_lu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: x509_lu.c,v 1.41 2021/11/05 17:06:42 tb Exp $ */
+/* $OpenBSD: x509_lu.c,v 1.42 2021/11/05 17:08:12 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -186,40 +186,30 @@ x509_object_cmp(const X509_OBJECT * const *a, const X509_OBJECT * const *b)
X509_STORE *
X509_STORE_new(void)
{
- X509_STORE *ret;
+ X509_STORE *store;
- if ((ret = malloc(sizeof(X509_STORE))) == NULL)
- return NULL;
- ret->objs = sk_X509_OBJECT_new(x509_object_cmp);
- ret->cache = 1;
- ret->get_cert_methods = sk_X509_LOOKUP_new_null();
- ret->verify = 0;
- ret->verify_cb = 0;
+ if ((store = calloc(1, sizeof(*store))) == NULL)
+ goto err;
- if ((ret->param = X509_VERIFY_PARAM_new()) == NULL)
+ if ((store->objs = sk_X509_OBJECT_new(x509_object_cmp)) == NULL)
+ goto err;
+ if ((store->get_cert_methods = sk_X509_LOOKUP_new_null()) == NULL)
+ goto err;
+ if ((store->param = X509_VERIFY_PARAM_new()) == NULL)
goto err;
- ret->get_issuer = 0;
- ret->check_issued = 0;
- ret->check_revocation = 0;
- ret->get_crl = 0;
- ret->check_crl = 0;
- ret->cert_crl = 0;
- ret->lookup_certs = 0;
- ret->lookup_crls = 0;
- ret->cleanup = 0;
-
- if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data))
+ if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, store,
+ &store->ex_data))
goto err;
- ret->references = 1;
- return ret;
+ store->references = 1;
+
+ return store;
+
+ err:
+ X509error(ERR_R_MALLOC_FAILURE);
+ X509_STORE_free(store);
-err:
- X509_VERIFY_PARAM_free(ret->param);
- sk_X509_LOOKUP_free(ret->get_cert_methods);
- sk_X509_OBJECT_free(ret->objs);
- free(ret);
return NULL;
}