diff options
Diffstat (limited to 'src/lib/libcrypto/x509/x509name.c')
-rw-r--r-- | src/lib/libcrypto/x509/x509name.c | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/src/lib/libcrypto/x509/x509name.c b/src/lib/libcrypto/x509/x509name.c index 319d79d74f..ecdf473ea9 100644 --- a/src/lib/libcrypto/x509/x509name.c +++ b/src/lib/libcrypto/x509/x509name.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x509name.c,v 1.33 2023/05/03 07:13:18 beck Exp $ */ | 1 | /* $OpenBSD: x509name.c,v 1.34 2023/05/03 08:10:23 beck 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 | * |
@@ -66,7 +66,6 @@ | |||
66 | #include <openssl/stack.h> | 66 | #include <openssl/stack.h> |
67 | #include <openssl/x509.h> | 67 | #include <openssl/x509.h> |
68 | 68 | ||
69 | #include "bytestring.h" | ||
70 | #include "x509_local.h" | 69 | #include "x509_local.h" |
71 | 70 | ||
72 | int | 71 | int |
@@ -85,37 +84,21 @@ int | |||
85 | X509_NAME_get_text_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, char *buf, | 84 | X509_NAME_get_text_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, char *buf, |
86 | int len) | 85 | int len) |
87 | { | 86 | { |
88 | unsigned char *text = NULL; | 87 | int i; |
89 | ASN1_STRING *data; | 88 | ASN1_STRING *data; |
90 | int i, text_len; | ||
91 | int ret = -1; | ||
92 | CBS cbs; | ||
93 | 89 | ||
94 | i = X509_NAME_get_index_by_OBJ(name, obj, -1); | 90 | i = X509_NAME_get_index_by_OBJ(name, obj, -1); |
95 | if (i < 0) | 91 | if (i < 0) |
96 | goto err; | 92 | return (-1); |
97 | data = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, i)); | 93 | data = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, i)); |
98 | /* | 94 | i = (data->length > (len - 1)) ? (len - 1) : data->length; |
99 | * Fail if we cannot encode as UTF-8, or if the UTF-8 encoding of the | 95 | if (buf == NULL) |
100 | * string contains a 0 byte, because mortal callers seldom handle the | 96 | return (data->length); |
101 | * length difference correctly | 97 | if (i >= 0) { |
102 | */ | 98 | memcpy(buf, data->data, i); |
103 | if ((text_len = ASN1_STRING_to_UTF8(&text, data)) < 0) | 99 | buf[i] = '\0'; |
104 | goto err; | ||
105 | CBS_init(&cbs, text, text_len); | ||
106 | if (CBS_contains_zero_byte(&cbs)) | ||
107 | goto err; | ||
108 | /* We still support the "pass NULL to find out how much" API */ | ||
109 | if (buf != NULL) { | ||
110 | if (len <= 0 || !CBS_write_bytes(&cbs, buf, len - 1, NULL)) | ||
111 | goto err; | ||
112 | /* It must be a C string */ | ||
113 | buf[text_len] = '\0'; | ||
114 | } | 100 | } |
115 | ret = text_len; | 101 | return (i); |
116 | err: | ||
117 | free(text); | ||
118 | return (ret); | ||
119 | } | 102 | } |
120 | LCRYPTO_ALIAS(X509_NAME_get_text_by_OBJ); | 103 | LCRYPTO_ALIAS(X509_NAME_get_text_by_OBJ); |
121 | 104 | ||