summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-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}