← ALL ADVISORIES

HIGH BYTERAY-2026-0308Patched

wolfSSL — Stack Buffer Overflow Printing Subject Alternative Names in C89 Builds

In --enable-c89 builds the OpenSSL-compatibility X.509 printer formats a certificate's subjectAltName strings into an 80-byte stack buffer with a macro that discards the size, so a long alt name from a peer certificate overflows the stack when the certificate is printed.

Advisory
BYTERAY-2026-0308
CWE
CWE-121
CVSS
8.1 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H)
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-27
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 through 5.9.4, builds with --enable-c89 and the OpenSSL X.509 print API
Fixed in
Master commit 9600d4d895f9a1d7925d9e2682f2ceacb8fca727 (PR 11682, merged 2026-10-15). Not in a wolfSSL stable release as of 2026-12-03.
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

wolfSSL's OpenSSL-compatibility layer can print a parsed certificate in human-readable form. For the subjectAltName extension it copies each alternative name into an 80-byte buffer on the stack with XSNPRINTF(scratch, MAX_WIDTH, "DNS:%s", entry->name) and the matching email: and URI: forms.

XSNPRINTF is meant to bound the write to the buffer size. In a build configured with --enable-c89 the macro is defined as sprintf and the size argument is dropped. A DNS, rfc822 or URI alternative name longer than the buffer is then written past the end of the stack buffer. The name string comes verbatim from the certificate and its length is not capped anywhere on the parse path, so a peer that presents a certificate with an oversized alt name controls the length and the content of the overflow.

Default ./configure builds map XSNPRINTF to snprintf, the write is bounded, and the defect does not arise. The overflow is specific to --enable-c89 builds that use the OpenSSL X.509 print API on attacker-supplied certificates.

Affected Products and Versions

  • Component: OpenSSL-compatibility X.509 printer, X509_print_name_entry() in src/x509.c, reached from wolfSSL_X509_print, wolfSSL_X509_print_ex and wolfSSL_X509_print_fp.
  • Required build: --enable-c89 (defines WOLF_C89, configure.ac:9024-9035; or the CMake option WOLFSSL_C89, CMakeLists.txt:3697-3704) together with OPENSSL_EXTRA/OPENSSL_ALL and a BIO (!NO_BIO).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2). The DNS:, email: and URI: sinks are at src/x509.c:7004, src/x509.c:7021 and src/x509.c:7034.
  • The v5.9.2-stable tag has the same sinks, and the v5.9.4-stable tag is identical to the tested tree here.
  • Fixed on master by 9600d4d895f9a1d7925d9e2682f2ceacb8fca727 (PR 11682, merged 2026-10-15). No stable release contains the fix as of 2026-12-03.
  • A default ./configure build maps XSNPRINTF to snprintf and is not affected.
  • Earlier releases were not checked.

Technical Details

The portability macro, under WOLF_C89, discards the destination size:

#elif defined(WOLF_C89)
    #define XSNPRINTF(f, len, ...) sprintf(f, __VA_ARGS__)

X509_print_name_entry() formats each alternative name into a fixed buffer:

char scratch[MAX_WIDTH];           /* MAX_WIDTH is 80 */
...
if (entry->type == ASN_DNS_TYPE) {
    len = XSNPRINTF(scratch, MAX_WIDTH, "DNS:%s", entry->name);
}
...
if (len >= MAX_WIDTH) {            /* runs after the write */
    ret = WOLFSSL_FAILURE;
    break;
}

With sprintf the MAX_WIDTH argument is ignored. Any entry->name longer than about 75 bytes (80 minus the "DNS:" prefix and the NUL) is written past scratch. The len >= MAX_WIDTH check at src/x509.c:7060 runs after sprintf has already written out of bounds, so it cannot prevent the overflow. The email: sink at src/x509.c:7021 and the URI: sink at src/x509.c:7034 behave the same way.

The string length is attacker-controlled:

  1. A peer presents a certificate whose subjectAltName carries a long dNSName, rfc822Name or URI. DecodeGeneralName() stores the entry at the certificate's own length (wolfcrypt/src/asn.c:20539-20545).
  2. SetDNSEntry() heap-allocates strLen + 1 bytes, copies the string and NUL-terminates it with no length cap (wolfcrypt/src/asn.c:15206-15219).
  3. The entries are copied into the WOLFSSL_X509 object as altNames (src/internal.c:15698-15711).
  4. The application prints the certificate: wolfSSL_X509_print (src/x509.c:8140) → wolfSSL_X509_print_ex (src/x509.c:8056) → X509PrintExtensions (src/x509.c:8124) → X509PrintSubjAltName (src/x509.c:7357-7362, dispatched at src/x509.c:7450) → X509_print_name_entry (src/x509.c:6973).
  5. The sink at src/x509.c:7004 writes the full name into scratch[80].

The IP Address: and Registered ID: cases in the same function print the generated ipString (at most 46 bytes) and ridString, not the raw certificate bytes, so the attacker-length-controlled overflow is the DNS, email and URI path.

Reachability and Preconditions

  • Build flags: --enable-c89 (WOLF_C89) and OPENSSL_EXTRA/OPENSSL_ALL with a BIO. A default build is not affected.
  • Runtime: the application calls wolfSSL_X509_print, wolfSSL_X509_print_ex or wolfSSL_X509_print_fp on a certificate obtained from an untrusted source.
  • Attacker position: any party that can hand the application a certificate to print — a TLS peer whose certificate is logged from a verify callback, or a tool that dumps a supplied certificate. Signature verification is not required; an unverified certificate is still parsed and printed.
  • No authentication or user interaction is required beyond the application choosing to print the certificate.

Impact

Where the preconditions hold, a certificate with an oversized subjectAltName string produces a stack buffer overflow in the process that prints it. The attacker controls both the length and the content of the bytes written past the 80-byte buffer, which is the primitive for overwriting adjacent stack state, including the saved return address.

ByteRay reproduced the overflow on an --enable-opensslextra --enable-c89 build. A self-signed certificate carrying a 200-byte dNSName, printed with wolfSSL_X509_print, produced an AddressSanitizer stack-buffer-overflow write of 205 bytes (strlen("DNS:") + 200 + 1) from sprintf called in X509_print_name_entry, smashing the 80-byte scratch and adjacent stack objects; a companion certificate drove the email: and URI: sinks the same way. A benign certificate printed cleanly on the same build.

Confirmed: a deterministic, attacker-controlled stack overflow and a reliable crash. Not independently verified: reliable control-flow hijack, which depends on the target's stack layout and mitigations.

Remediation and Mitigation

Use a master build that contains 9600d4d895f9a1d7925d9e2682f2ceacb8fca727 (PR 11682). That change rewrites X509_print_name_entry() so the DNS, email and URI alternative names are written to the BIO through a bounded escaping helper rather than formatted into the stack buffer, which removes the unbounded write. The XSNPRINTF-to-sprintf mapping itself is unchanged; the sink is fixed. The fix is on master only; no stable release contains it as of 2026-12-03.

Until an update is possible, build without --enable-c89 so XSNPRINTF maps to snprintf and the writes are bounded, or do not print untrusted certificates through the OpenSSL-compatibility print API in a C89 build.

Timeline

  • 2026-09-27 — Reported to wolfSSL.
  • 2026-10-07 — PR 11682 opened, escaping and bounding the X.509 print output.
  • 2026-10-15 — PR 11682 merged to master.
  • 2026-12-03 — Public disclosure.

Credits

Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.

References