Skip to content

Commit ccb0a11

Browse files
committed
Fix a read buffer overrun in X509_CERT_AUX_print()
This is a backport of commit c5dc9ab to 1.0.2. That commit fixed the same bug but in master/1.1.1 it is in the function X509_aux_print(). The original commit had the following description: Fix a read buffer overrun in X509_aux_print(). The ASN1_STRING_get0_data(3) manual explitely cautions the reader that the data is not necessarily NUL-terminated, and the function X509_alias_set1(3) does not sanitize the data passed into it in any way either, so we must assume the return value from X509_alias_get0(3) is merely a byte array and not necessarily a string in the sense of the C language. I found this bug while writing manual pages for X509_print_ex(3) and related functions. Theo Buehler <tb@openbsd.org> checked my patch to fix the same bug in LibreSSL, see http://cvsweb.openbsd.org/src/lib/libcrypto/asn1/t_x509a.c#rev1.9 As an aside, note that the function still produces incomplete and misleading results when the data contains a NUL byte in the middle and that error handling is consistently absent throughout, even though the function provides an "int" return value obviously intended to be 1 for success and 0 for failure, and even though this function is called by another function that also wants to return 1 for success and 0 for failure and even does so in many of its code paths, though not in others. But let's stay focussed. Many things would be nice to have in the wide wild world, but a buffer overflow must not be allowed to remain in our backyard. CVE-2021-3712 Reviewed-by: Paul Dale <pauli@openssl.org>
1 parent 792082b commit ccb0a11

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Diff for: crypto/asn1/t_x509a.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ int X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent)
104104
} else
105105
BIO_printf(out, "%*sNo Rejected Uses.\n", indent, "");
106106
if (aux->alias)
107-
BIO_printf(out, "%*sAlias: %s\n", indent, "", aux->alias->data);
107+
BIO_printf(out, "%*sAlias: %.*s\n", indent, "", aux->alias->length,
108+
aux->alias->data);
108109
if (aux->keyid) {
109110
BIO_printf(out, "%*sKey Id: ", indent, "");
110111
for (i = 0; i < aux->keyid->length; i++)

0 commit comments

Comments
 (0)