diff options
-rw-r--r-- | src/lib/libcrypto/asn1/a_string.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/lib/libcrypto/asn1/a_string.c b/src/lib/libcrypto/asn1/a_string.c index 4501c18729..411c9bc909 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.9 2022/05/16 20:44:17 tb Exp $ */ | 1 | /* $OpenBSD: a_string.c,v 1.10 2022/05/16 20:51:26 tb 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 | * |
@@ -276,24 +276,35 @@ ASN1_STRING_print(BIO *bp, const ASN1_STRING *astr) | |||
276 | int | 276 | int |
277 | ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in) | 277 | ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in) |
278 | { | 278 | { |
279 | ASN1_STRING stmp = { 0 }; | 279 | ASN1_STRING *astr = NULL; |
280 | ASN1_STRING *str = &stmp; | 280 | int mbflag; |
281 | int mbflag, ret; | 281 | int ret = -1; |
282 | |||
283 | if (out == NULL || *out != NULL) | ||
284 | goto err; | ||
282 | 285 | ||
283 | if (in == NULL) | 286 | if (in == NULL) |
284 | return -1; | 287 | goto err; |
285 | 288 | ||
286 | if ((mbflag = asn1_tag2charwidth(in->type)) == -1) | 289 | if ((mbflag = asn1_tag2charwidth(in->type)) == -1) |
287 | return -1; | 290 | goto err; |
288 | 291 | ||
289 | mbflag |= MBSTRING_FLAG; | 292 | mbflag |= MBSTRING_FLAG; |
290 | 293 | ||
291 | ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, | 294 | if ((ret = ASN1_mbstring_copy(&astr, in->data, in->length, mbflag, |
292 | B_ASN1_UTF8STRING); | 295 | B_ASN1_UTF8STRING)) < 0) |
293 | if (ret < 0) | 296 | goto err; |
294 | return ret; | 297 | |
295 | *out = stmp.data; | 298 | *out = astr->data; |
296 | return stmp.length; | 299 | ret = astr->length; |
300 | |||
301 | astr->data = NULL; | ||
302 | astr->length = 0; | ||
303 | |||
304 | err: | ||
305 | ASN1_STRING_free(astr); | ||
306 | |||
307 | return ret; | ||
297 | } | 308 | } |
298 | 309 | ||
299 | int | 310 | int |