diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2021-06-23 14:26:22 +0200 |
---|---|---|
committer | Dr. David von Oheimb <dev@ddvo.net> | 2021-06-25 07:44:50 +0200 |
commit | cfd854a55e45626dd094f5d3846fd56fb4ec3cbf (patch) | |
tree | 4b733a0b51b15267ccae463d3b6a24fc4ed49480 /crypto/asn1 | |
parent | 7b3990e3f8c1d68c2afeb02a8f08f18f08916b95 (diff) |
ossl_sk_ASN1_UTF8STRING2text(): Minor generalization and refactoring for readability
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15879)
Diffstat (limited to 'crypto/asn1')
-rw-r--r-- | crypto/asn1/asn1_lib.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/crypto/asn1/asn1_lib.c b/crypto/asn1/asn1_lib.c index b1fa6b55a0..bdd0ec488d 100644 --- a/crypto/asn1/asn1_lib.c +++ b/crypto/asn1/asn1_lib.c @@ -413,9 +413,9 @@ unsigned char *ASN1_STRING_data(ASN1_STRING *x) } #endif +/* |max_len| excludes NUL terminator and may be 0 to indicate no restriction */ char *ossl_sk_ASN1_UTF8STRING2text(STACK_OF(ASN1_UTF8STRING) *text, - const char *sep, - size_t max_len /* excluding NUL terminator */) + const char *sep, size_t max_len) { int i; ASN1_UTF8STRING *current; @@ -423,26 +423,27 @@ char *ossl_sk_ASN1_UTF8STRING2text(STACK_OF(ASN1_UTF8STRING) *text, char *result = NULL; char *p; - if (!ossl_assert(sep != NULL)) - return NULL; + if (sep == NULL) + sep = ""; sep_len = strlen(sep); - for (i = 0; i < sk_ASN1_UTF8STRING_num(text); ++i) { + for (i = 0; i < sk_ASN1_UTF8STRING_num(text); i++) { current = sk_ASN1_UTF8STRING_value(text, i); if (i > 0) length += sep_len; length += ASN1_STRING_length(current); - if (length > max_len) + if (max_len != 0 && length > max_len) return NULL; } if ((result = OPENSSL_malloc(length + 1)) == NULL) return NULL; - for (i = 0, p = result; i < sk_ASN1_UTF8STRING_num(text); ++i) { + p = result; + for (i = 0; i < sk_ASN1_UTF8STRING_num(text); i++) { current = sk_ASN1_UTF8STRING_value(text, i); length = ASN1_STRING_length(current); if (i > 0 && sep_len > 0) { - strncpy(p, sep, sep_len + 1); + strncpy(p, sep, sep_len + 1); /* using + 1 to silence gcc warning */ p += sep_len; } strncpy(p, (const char *)ASN1_STRING_get0_data(current), length); |