summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2019-04-16 19:42:20 +0000
committertb <>2019-04-16 19:42:20 +0000
commit8db0fb09968c8b153cd6c30bdff10ee3a4d5a71f (patch)
tree1025850163b28cfb6b4313d66b80f391d58496e6 /src/lib
parent37f8724cb7f0a2c25fa9cef57235cf2a839e25f3 (diff)
downloadopenbsd-8db0fb09968c8b153cd6c30bdff10ee3a4d5a71f.tar.gz
openbsd-8db0fb09968c8b153cd6c30bdff10ee3a4d5a71f.tar.bz2
openbsd-8db0fb09968c8b153cd6c30bdff10ee3a4d5a71f.zip
Rewrite & fix X509V3_add_value()
X509V3_add_value() helpfully allocates a STACK_OF(CONF_VALUE) if it receives a pointer to a NULL pointer. If anything fails along the way, it is however the caller's responsibility to free it. This can easily be fixed by freeing *extlist in the error path and zeroing it to avoid a double free if there happens to be a caller out there that avoids the leak. Polish a few things so the function conforms a bit better to our usual style. tweak & ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/x509v3/v3_utl.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/lib/libcrypto/x509v3/v3_utl.c b/src/lib/libcrypto/x509v3/v3_utl.c
index c01edf4e3c..a051baae62 100644
--- a/src/lib/libcrypto/x509v3/v3_utl.c
+++ b/src/lib/libcrypto/x509v3/v3_utl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_utl.c,v 1.36 2019/04/16 19:34:15 tb Exp $ */ 1/* $OpenBSD: v3_utl.c,v 1.37 2019/04/16 19:42:20 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 */
@@ -79,35 +79,42 @@ static int ipv6_from_asc(unsigned char *v6, const char *in);
79static int ipv6_cb(const char *elem, int len, void *usr); 79static int ipv6_cb(const char *elem, int len, void *usr);
80static int ipv6_hex(unsigned char *out, const char *in, int inlen); 80static int ipv6_hex(unsigned char *out, const char *in, int inlen);
81 81
82/* Add a CONF_VALUE name value pair to stack */ 82/* Add a CONF_VALUE name-value pair to stack. */
83
84int 83int
85X509V3_add_value(const char *name, const char *value, 84X509V3_add_value(const char *name, const char *value,
86 STACK_OF(CONF_VALUE) **extlist) 85 STACK_OF(CONF_VALUE) **extlist)
87{ 86{
88 CONF_VALUE *vtmp = NULL; 87 CONF_VALUE *vtmp = NULL;
89 char *tname = NULL, *tvalue = NULL; 88 STACK_OF(CONF_VALUE) *free_exts = NULL;
90 89
91 if (name && !(tname = strdup(name))) 90 if ((vtmp = calloc(1, sizeof(CONF_VALUE))) == NULL)
92 goto err;
93 if (value && !(tvalue = strdup(value)))
94 goto err;
95 if (!(vtmp = malloc(sizeof(CONF_VALUE))))
96 goto err;
97 if (!*extlist && !(*extlist = sk_CONF_VALUE_new_null()))
98 goto err; 91 goto err;
99 vtmp->section = NULL; 92 if (name != NULL) {
100 vtmp->name = tname; 93 if ((vtmp->name = strdup(name)) == NULL)
101 vtmp->value = tvalue; 94 goto err;
95 }
96 if (value != NULL) {
97 if ((vtmp->value = strdup(value)) == NULL)
98 goto err;
99 }
100
101 if (*extlist == NULL) {
102 if ((free_exts = *extlist = sk_CONF_VALUE_new_null()) == NULL)
103 goto err;
104 }
105
102 if (!sk_CONF_VALUE_push(*extlist, vtmp)) 106 if (!sk_CONF_VALUE_push(*extlist, vtmp))
103 goto err; 107 goto err;
108
104 return 1; 109 return 1;
105 110
106 err: 111 err:
107 X509V3error(ERR_R_MALLOC_FAILURE); 112 X509V3error(ERR_R_MALLOC_FAILURE);
108 free(vtmp); 113 X509V3_conf_free(vtmp);
109 free(tname); 114 if (free_exts != NULL) {
110 free(tvalue); 115 sk_CONF_VALUE_free(*extlist);
116 *extlist = NULL;
117 }
111 return 0; 118 return 0;
112} 119}
113 120