summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2022-03-14 16:35:45 +0000
committerjsing <>2022-03-14 16:35:45 +0000
commitf3380f46eb991038b5106c03e9edc8021bae09cb (patch)
tree0a703c58e62599ddd72029bc630ee4c4257f956d
parent3ee3bfddb797dd4bd1f53d204395e7f5198a8180 (diff)
downloadopenbsd-f3380f46eb991038b5106c03e9edc8021bae09cb.tar.gz
openbsd-f3380f46eb991038b5106c03e9edc8021bae09cb.tar.bz2
openbsd-f3380f46eb991038b5106c03e9edc8021bae09cb.zip
Factor out ASN1_STRING clearing code.
This fixes a bug in ASN1_STRING_set0() where it does not respect the ASN1_STRING_FLAG_NDEF flag and potentially frees memory that we do not own. ok inguchi@ tb@
-rw-r--r--src/lib/libcrypto/asn1/a_string.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/lib/libcrypto/asn1/a_string.c b/src/lib/libcrypto/asn1/a_string.c
index 2b5840e9e0..217d28da09 100644
--- a/src/lib/libcrypto/asn1/a_string.c
+++ b/src/lib/libcrypto/asn1/a_string.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_string.c,v 1.5 2022/03/14 16:23:29 jsing Exp $ */ 1/* $OpenBSD: a_string.c,v 1.6 2022/03/14 16:35:45 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -85,14 +85,24 @@ ASN1_STRING_type_new(int type)
85 return astr; 85 return astr;
86} 86}
87 87
88static void
89ASN1_STRING_clear(ASN1_STRING *astr)
90{
91 if (!(astr->flags & ASN1_STRING_FLAG_NDEF))
92 freezero(astr->data, astr->length);
93
94 astr->flags &= ~ASN1_STRING_FLAG_NDEF;
95 astr->data = NULL;
96 astr->length = 0;
97}
98
88void 99void
89ASN1_STRING_free(ASN1_STRING *astr) 100ASN1_STRING_free(ASN1_STRING *astr)
90{ 101{
91 if (astr == NULL) 102 if (astr == NULL)
92 return; 103 return;
93 104
94 if (astr->data != NULL && !(astr->flags & ASN1_STRING_FLAG_NDEF)) 105 ASN1_STRING_clear(astr);
95 freezero(astr->data, astr->length);
96 106
97 free(astr); 107 free(astr);
98} 108}
@@ -176,7 +186,8 @@ ASN1_STRING_set(ASN1_STRING *astr, const void *_data, int len)
176void 186void
177ASN1_STRING_set0(ASN1_STRING *astr, void *data, int len) 187ASN1_STRING_set0(ASN1_STRING *astr, void *data, int len)
178{ 188{
179 freezero(astr->data, astr->length); 189 ASN1_STRING_clear(astr);
190
180 astr->data = data; 191 astr->data = data;
181 astr->length = len; 192 astr->length = len;
182} 193}