summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2024-11-06 08:59:33 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2024-11-06 08:59:33 +0000
commitedbb836b22dc787c52fe2b7f4e129a71cf7c3d37 (patch)
tree5b7e71936222235e89a753c5a515cca5eb56e22c /lib
parent05148037b10f864dbda738b10010b13513cff6a1 (diff)
Switch EC_GROUP_new() to calloc()
Use a single cleanup path, use calloc rather than setting several members to 0/NULL. This has the side effect that finished can be called even when init() wasn't called, but this isn't an issue with our EC_GROUP_METHODs. ok jsing
Diffstat (limited to 'lib')
-rw-r--r--lib/libcrypto/ec/ec_lib.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/lib/libcrypto/ec/ec_lib.c b/lib/libcrypto/ec/ec_lib.c
index 15e5055f34e..c02f054cdc2 100644
--- a/lib/libcrypto/ec/ec_lib.c
+++ b/lib/libcrypto/ec/ec_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ec_lib.c,v 1.79 2024/11/05 08:56:57 tb Exp $ */
+/* $OpenBSD: ec_lib.c,v 1.80 2024/11/06 08:59:32 tb Exp $ */
/*
* Originally written by Bodo Moeller for the OpenSSL project.
*/
@@ -80,39 +80,38 @@
EC_GROUP *
EC_GROUP_new(const EC_METHOD *meth)
{
- EC_GROUP *ret;
+ EC_GROUP *group = NULL;
if (meth == NULL) {
ECerror(EC_R_SLOT_FULL);
- return NULL;
+ goto err;
}
if (meth->group_init == NULL) {
ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
- return NULL;
+ goto err;
}
- ret = malloc(sizeof *ret);
- if (ret == NULL) {
+ if ((group = calloc(1, sizeof(*group))) == NULL) {
ECerror(ERR_R_MALLOC_FAILURE);
- return NULL;
+ goto err;
}
- ret->meth = meth;
- ret->generator = NULL;
- BN_init(&ret->order);
- BN_init(&ret->cofactor);
+ group->meth = meth;
- ret->curve_name = 0;
- ret->asn1_flag = OPENSSL_EC_NAMED_CURVE;
- ret->asn1_form = POINT_CONVERSION_UNCOMPRESSED;
+ BN_init(&group->order);
+ BN_init(&group->cofactor);
- ret->seed = NULL;
- ret->seed_len = 0;
+ group->asn1_flag = OPENSSL_EC_NAMED_CURVE;
+ group->asn1_form = POINT_CONVERSION_UNCOMPRESSED;
- if (!meth->group_init(ret)) {
- free(ret);
- return NULL;
- }
- return ret;
+ if (!meth->group_init(group))
+ goto err;
+
+ return group;
+
+ err:
+ EC_GROUP_free(group);
+
+ return NULL;
}
LCRYPTO_ALIAS(EC_GROUP_new);