diff options
author | jsing <> | 2022-03-14 16:35:45 +0000 |
---|---|---|
committer | jsing <> | 2022-03-14 16:35:45 +0000 |
commit | f3380f46eb991038b5106c03e9edc8021bae09cb (patch) | |
tree | 0a703c58e62599ddd72029bc630ee4c4257f956d | |
parent | 3ee3bfddb797dd4bd1f53d204395e7f5198a8180 (diff) | |
download | openbsd-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.c | 19 |
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 | ||
88 | static void | ||
89 | ASN1_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 | |||
88 | void | 99 | void |
89 | ASN1_STRING_free(ASN1_STRING *astr) | 100 | ASN1_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) | |||
176 | void | 186 | void |
177 | ASN1_STRING_set0(ASN1_STRING *astr, void *data, int len) | 187 | ASN1_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 | } |