diff options
| author | tb <> | 2024-08-31 18:38:46 +0000 |
|---|---|---|
| committer | tb <> | 2024-08-31 18:38:46 +0000 |
| commit | 8da74b639c99ef7f7df5bdef18fffa5f7528918d (patch) | |
| tree | 69a256f5a696be2112fdda95d9697a8ebd92e4d8 /src | |
| parent | 00facdf494047c726bb583cad1632021a161e271 (diff) | |
| download | openbsd-8da74b639c99ef7f7df5bdef18fffa5f7528918d.tar.gz openbsd-8da74b639c99ef7f7df5bdef18fffa5f7528918d.tar.bz2 openbsd-8da74b639c99ef7f7df5bdef18fffa5f7528918d.zip | |
Rewrite X509V3_add_value() to a single exit idiom
ok jsing
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/x509/x509_utl.c | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/src/lib/libcrypto/x509/x509_utl.c b/src/lib/libcrypto/x509/x509_utl.c index 6f5add482f..f327e9fca7 100644 --- a/src/lib/libcrypto/x509/x509_utl.c +++ b/src/lib/libcrypto/x509/x509_utl.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: x509_utl.c,v 1.21 2024/08/31 10:03:03 tb Exp $ */ | 1 | /* $OpenBSD: x509_utl.c,v 1.22 2024/08/31 18:38:46 tb Exp $ */ |
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 3 | * project. | 3 | * project. |
| 4 | */ | 4 | */ |
| @@ -87,40 +87,53 @@ static int ipv6_hex(unsigned char *out, const char *in, int inlen); | |||
| 87 | /* Add a CONF_VALUE name-value pair to stack. */ | 87 | /* Add a CONF_VALUE name-value pair to stack. */ |
| 88 | int | 88 | int |
| 89 | X509V3_add_value(const char *name, const char *value, | 89 | X509V3_add_value(const char *name, const char *value, |
| 90 | STACK_OF(CONF_VALUE) **extlist) | 90 | STACK_OF(CONF_VALUE) **out_extlist) |
| 91 | { | 91 | { |
| 92 | CONF_VALUE *vtmp = NULL; | 92 | STACK_OF(CONF_VALUE) *extlist = NULL; |
| 93 | STACK_OF(CONF_VALUE) *free_exts = NULL; | 93 | CONF_VALUE *conf_value = NULL; |
| 94 | int ret = 0; | ||
| 94 | 95 | ||
| 95 | if ((vtmp = calloc(1, sizeof(CONF_VALUE))) == NULL) | 96 | if ((conf_value = calloc(1, sizeof(*conf_value))) == NULL) { |
| 97 | X509V3error(ERR_R_MALLOC_FAILURE); | ||
| 96 | goto err; | 98 | goto err; |
| 99 | } | ||
| 97 | if (name != NULL) { | 100 | if (name != NULL) { |
| 98 | if ((vtmp->name = strdup(name)) == NULL) | 101 | if ((conf_value->name = strdup(name)) == NULL) { |
| 102 | X509V3error(ERR_R_MALLOC_FAILURE); | ||
| 99 | goto err; | 103 | goto err; |
| 104 | } | ||
| 100 | } | 105 | } |
| 101 | if (value != NULL) { | 106 | if (value != NULL) { |
| 102 | if ((vtmp->value = strdup(value)) == NULL) | 107 | if ((conf_value->value = strdup(value)) == NULL) { |
| 108 | X509V3error(ERR_R_MALLOC_FAILURE); | ||
| 103 | goto err; | 109 | goto err; |
| 110 | } | ||
| 104 | } | 111 | } |
| 105 | 112 | ||
| 106 | if (*extlist == NULL) { | 113 | if ((extlist = *out_extlist) == NULL) |
| 107 | if ((free_exts = *extlist = sk_CONF_VALUE_new_null()) == NULL) | 114 | extlist = sk_CONF_VALUE_new_null(); |
| 108 | goto err; | 115 | if (extlist == NULL) { |
| 116 | X509V3error(ERR_R_MALLOC_FAILURE); | ||
| 117 | goto err; | ||
| 109 | } | 118 | } |
| 110 | 119 | ||
| 111 | if (!sk_CONF_VALUE_push(*extlist, vtmp)) | 120 | if (!sk_CONF_VALUE_push(extlist, conf_value)) { |
| 121 | X509V3error(ERR_R_MALLOC_FAILURE); | ||
| 112 | goto err; | 122 | goto err; |
| 123 | } | ||
| 124 | conf_value = NULL; | ||
| 113 | 125 | ||
| 114 | return 1; | 126 | *out_extlist = extlist; |
| 127 | extlist = NULL; | ||
| 128 | |||
| 129 | ret = 1; | ||
| 115 | 130 | ||
| 116 | err: | 131 | err: |
| 117 | X509V3error(ERR_R_MALLOC_FAILURE); | 132 | if (extlist != *out_extlist) |
| 118 | X509V3_conf_free(vtmp); | 133 | sk_CONF_VALUE_pop_free(extlist, X509V3_conf_free); |
| 119 | if (free_exts != NULL) { | 134 | X509V3_conf_free(conf_value); |
| 120 | sk_CONF_VALUE_free(*extlist); | 135 | |
| 121 | *extlist = NULL; | 136 | return ret; |
| 122 | } | ||
| 123 | return 0; | ||
| 124 | } | 137 | } |
| 125 | 138 | ||
| 126 | int | 139 | int |
