From dcc2b9cff833ae1d7a629e83871041a1a80e8704 Mon Sep 17 00:00:00 2001 From: tb Date: Sat, 31 Aug 2024 18:39:25 +0000 Subject: [PATCH] sync x509v3_add_value with x509_utl.c --- usr.bin/openssl/ocsp.c | 51 ++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/usr.bin/openssl/ocsp.c b/usr.bin/openssl/ocsp.c index ace843cce1d..d35940a7aed 100644 --- a/usr.bin/openssl/ocsp.c +++ b/usr.bin/openssl/ocsp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ocsp.c,v 1.25 2024/08/30 17:26:44 tb Exp $ */ +/* $OpenBSD: ocsp.c,v 1.26 2024/08/31 18:39:25 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2000. */ @@ -187,40 +187,53 @@ ocsp_opt_cert_id_md(int argc, char **argv, int *argsused) static 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; } static int -- 2.20.1