diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2024-08-31 18:38:47 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2024-08-31 18:38:47 +0000 |
commit | 199860d7edae2f3963cbd9245aed4ba483916bc4 (patch) | |
tree | 6d5da66418b2f543e73ac834e68a9079a0e5a33f /lib/libcrypto | |
parent | ee2b4ffadd45f3f4c92ce2d4412f248b22e20bad (diff) |
Rewrite X509V3_add_value() to a single exit idiom
ok jsing
Diffstat (limited to 'lib/libcrypto')
-rw-r--r-- | lib/libcrypto/x509/x509_utl.c | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/lib/libcrypto/x509/x509_utl.c b/lib/libcrypto/x509/x509_utl.c index 6f5add482fe..f327e9fca7f 100644 --- a/lib/libcrypto/x509/x509_utl.c +++ b/lib/libcrypto/x509/x509_utl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_utl.c,v 1.21 2024/08/31 10:03:03 tb Exp $ */ +/* $OpenBSD: x509_utl.c,v 1.22 2024/08/31 18:38:46 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project. */ @@ -87,40 +87,53 @@ static int ipv6_hex(unsigned char *out, const char *in, int inlen); /* Add a CONF_VALUE name-value pair to stack. */ int X509V3_add_value(const char *name, const char *value, - STACK_OF(CONF_VALUE) **extlist) + STACK_OF(CONF_VALUE) **out_extlist) { - CONF_VALUE *vtmp = NULL; - STACK_OF(CONF_VALUE) *free_exts = NULL; + STACK_OF(CONF_VALUE) *extlist = NULL; + CONF_VALUE *conf_value = NULL; + int ret = 0; - if ((vtmp = calloc(1, sizeof(CONF_VALUE))) == NULL) + if ((conf_value = calloc(1, sizeof(*conf_value))) == NULL) { + X509V3error(ERR_R_MALLOC_FAILURE); goto err; + } if (name != NULL) { - if ((vtmp->name = strdup(name)) == NULL) + if ((conf_value->name = strdup(name)) == NULL) { + X509V3error(ERR_R_MALLOC_FAILURE); goto err; + } } if (value != NULL) { - if ((vtmp->value = strdup(value)) == NULL) + if ((conf_value->value = strdup(value)) == NULL) { + X509V3error(ERR_R_MALLOC_FAILURE); goto err; + } } - if (*extlist == NULL) { - if ((free_exts = *extlist = sk_CONF_VALUE_new_null()) == NULL) - goto err; + if ((extlist = *out_extlist) == NULL) + extlist = sk_CONF_VALUE_new_null(); + if (extlist == NULL) { + X509V3error(ERR_R_MALLOC_FAILURE); + goto err; } - if (!sk_CONF_VALUE_push(*extlist, vtmp)) + if (!sk_CONF_VALUE_push(extlist, conf_value)) { + X509V3error(ERR_R_MALLOC_FAILURE); goto err; + } + conf_value = NULL; - return 1; + *out_extlist = extlist; + extlist = NULL; + + ret = 1; err: - X509V3error(ERR_R_MALLOC_FAILURE); - X509V3_conf_free(vtmp); - if (free_exts != NULL) { - sk_CONF_VALUE_free(*extlist); - *extlist = NULL; - } - return 0; + if (extlist != *out_extlist) + sk_CONF_VALUE_pop_free(extlist, X509V3_conf_free); + X509V3_conf_free(conf_value); + + return ret; } int |