wolfSSL — In-Place Modification of the Printed String in wolfSSL_ASN1_STRING_print
wolfSSL_ASN1_STRING_print replaces unprintable bytes with dots inside the string object it was asked to print, then writes that buffer out. Printing a certificate name therefore changes the name. Every later use of the same object, including comparisons and further prints, sees the altered bytes, and the certificate author chooses which positions change.
- Advisory
- BYTERAY-2026-0422
- CWE
- CWE-144
- CVSS
- 3.7 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:L/A:N)
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 through 5.9.4, builds with OPENSSL_EXTRA (--enable-opensslextra) whose application prints certificate strings with wolfSSL_ASN1_STRING_print or wolfSSL_GENERAL_NAME_print
- Fixed in
- Master commit 6b6698d5dde9368d361cba9681776ac341e6b0ff (PR 11734, merged 2026-11-05). Not in a wolfSSL stable release as of 2026-12-03.
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
wolfSSL_ASN1_STRING_print() is the OpenSSL-compatible routine for writing an ASN.1 string to a BIO with unprintable bytes shown as .. The wolfSSL implementation does the substitution in the caller's string object instead of in a copy. After the call the object no longer holds the bytes that were in the certificate.
The strings an application prints this way usually come from a certificate it received from a peer: subject alternative names, or attributes of the subject and issuer. A certificate author who puts control bytes in such a string decides which positions become dots the first time the application prints it. Code that prints a name for a log and then compares, stores or exports the same object works on different data from the data that was verified. There is no memory-safety effect, and the certificate's DER encoding is not touched. The function belongs to the OpenSSL compatibility layer, which a default build does not include.
Affected Products and Versions
- Component:
src/ssl_asn1.c,wolfSSL_ASN1_STRING_print(); called bywolfSSL_GENERAL_NAME_print()insrc/x509.c. - Required build:
OPENSSL_EXTRAwith BIO support (src/ssl_asn1.c:3428-3431);--enable-opensslextrais off by default (configure.ac:3314-3318).wolfSSL_GENERAL_NAME_print()needsOPENSSL_ALL(src/x509.c:5847). - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- The
v5.9.2-stableandv5.9.4-stabletags contain the same in-place substitution. - Fixed on master. No wolfSSL release contains the fix.
- A default
./configurebuild does not include this code. Earlier releases were not checked.
Technical Details
The whole function body is a substitution loop followed by a write of the same buffer (src/ssl_asn1.c:3467-3477):
len = str->length;
/* Convert all unprintable characters to '.'. */
for (i = 0; i < len; i++) {
if (wolfssl_unprintable_char(str->data[i])) {
str->data[i] = '.';
}
}
/* Write string to BIO. */
if (wolfSSL_BIO_write(bio, str->data, len) != len) {
len = 0;
}
str is the caller's object. The comment above the function notes that the conversion is destructive (src/ssl_asn1.c:3449). The classifier wolfssl_unprintable_char() takes a plain char and reports every value up to 31 except CR and LF (src/ssl_asn1.c:3438-3445). Where char is a signed type, bytes 0x80 to 0xFF compare as negative and are reported too, so the bytes of non-ASCII UTF-8 text are overwritten along with control bytes. The compatibility macro ASN1_STRING_print casts its argument to a non-const pointer (wolfssl/openssl/ssl.h:1087), so code ported from OpenSSL, where the parameter is const, can pass a string it does not expect to change.
Which object is modified depends on how the application obtained the string:
- Subject alternative names.
wolfSSL_X509_get_ext_d2i()builds a newGENERAL_NAMEstack on each call and copies each name into it (src/x509.c:2546-2551,src/x509.c:2653-2660).wolfSSL_GENERAL_NAME_print()passes the email, DNS and URI strings of such an entry towolfSSL_ASN1_STRING_print()(src/x509.c:5894,src/x509.c:5902,src/x509.c:5929). The modified object is the application's copy. The certificate object keeps the original bytes. - Subject and issuer attributes.
wolfSSL_X509_get_subject_name()returns the name stored in the certificate object (src/x509.c:6274-6280),wolfSSL_X509_NAME_get_entry()returns a pointer to an entry inside it (src/x509.c:14998-15018), andwolfSSL_X509_NAME_ENTRY_get_data()returns that entry's own string (src/x509.c:6835-6843). Passing it towolfSSL_ASN1_STRING_print()modifies the certificate object itself.
Reachability and Preconditions
- The application calls
wolfSSL_ASN1_STRING_print()orwolfSSL_GENERAL_NAME_print()on a string taken from a certificate it did not create. wolfSSL does not call either function during a handshake. - The application uses the same string object again after printing it.
- The string contains at least one byte the classifier reports. A TLS peer controls the contents of its own certificate, and a certificate that fails verification still reaches the application's verify callback as an object it can inspect and print (
src/internal.c:16320-16343).
Impact
Confirmed from source: after one print call, the bytes the classifier reports are permanently replaced by . in the object that was printed. For a GENERAL_NAME obtained from wolfSSL_X509_get_ext_d2i() the change is limited to the stack the application holds. For a subject or issuer entry it changes the WOLFSSL_X509 object, and later reads of that entry return the altered value. The certificate author controls which positions are altered but not what they become. Two different names can become equal after printing, for example names that differ only in a control byte or, where char is signed, in non-ASCII characters of the same length.
Not verified: ByteRay did not test any application, and did not confirm the signed-char behaviour by execution.
ByteRay did not build a proof of concept for this issue. The analysis is from source review.
Remediation and Mitigation
Fixed on master by commit 6b6698d5dde9368d361cba9681776ac341e6b0ff, part of PR 11734, merged 2026-11-05. The commit makes wolfSSL_ASN1_STRING_print() do the substitution in a temporary buffer and write that buffer, leaving the caller's string unchanged. A later commit in the same pull request allocates the temporary copy on the heap and writes it in one call. The fix is on master only. No wolfSSL release contains it as of 2026-12-03.
Until a release is available: do not reuse a string object after printing it with these functions. Print a duplicate made with wolfSSL_ASN1_STRING_dup(), or fetch the value again from the certificate after printing.
The same function also lets CR and LF through to the output. That behaviour is separate and is described in BYTERAY-2026-0344.
Timeline
- 2026-09-28 — Reported to wolfSSL.
- 2026-10-13 — Pull request 11734 opened upstream.
- 2026-11-05 — Pull request 11734 merged to master.
- 2026-12-03 — Public disclosure.
Credits
Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.