← ALL ADVISORIES

LOW BYTERAY-2026-0418Patched

wolfSSL — Stack Out-of-Bounds Write in X.509 Extension Line Printing in WOLF_C89 Builds

In WOLF_C89 builds the certificate printer formats each extension's OID text and criticality into an 80-byte stack buffer with an unbounded sprintf and checks the length afterwards. A critical extension with long numeric OID text writes up to six bytes past the buffer. The parser rejects unrecognised critical extensions, so only builds that accept certain critical extensions without naming them are exposed.

Advisory
BYTERAY-2026-0418
CWE
CWE-1177
CVSS
3.7 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L)
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-28
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 through 5.9.4, builds with WOLF_C89 (--enable-c89), OPENSSL_EXTRA and one of WOLFSSL_ACME_OID, WOLFSSL_DUAL_ALG_CERTS or WOLFSSL_NO_ASN_STRICT
Fixed in
Master commit 808be25236b3e151b6f3d0a5783fb19440235a6b (PR 11606, merged 2026-10-19). Not in a wolfSSL stable release as of 2026-12-03.
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

When the OpenSSL compatibility layer prints a certificate, X509PrintExtensions() writes one header line per extension: indentation, the extension name or its dotted-decimal OID, and : critical when the extension is critical. The line is formatted into an 80-byte stack buffer with XSNPRINTF and its length is tested afterwards. In a WOLF_C89 build XSNPRINTF is sprintf, so the test runs after the write.

An extension that has no name in the compatibility layer is printed as numeric OID text of up to 62 characters. With the indentation and the : critical suffix the line needs 86 bytes, six more than the buffer holds. Without the suffix the line fits.

The exposure is narrow. At the tested commit the certificate parser rejects a certificate that carries an unrecognised critical extension, and the printer then prints no extensions at all. The overflow is reachable only in builds where the parser accepts a critical extension that the compatibility layer cannot name. ByteRay identified three such configurations from the source. Default builds are not affected. This is one instance of the macro behaviour described in BYTERAY-2026-0339.

Affected Products and Versions

  • Component: OpenSSL compatibility layer, X509PrintExtensions() in src/x509.c.
  • Required build: WOLF_C89 (--enable-c89, configure.ac:9024-9035), OPENSSL_EXTRA without NO_BIO, and at least one of WOLFSSL_ACME_OID (set by --enable-tailscale, configure.ac:2003), WOLFSSL_DUAL_ALG_CERTS or WOLFSSL_NO_ASN_STRICT.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • The v5.9.4-stable tag has the same code. The v5.9.2-stable tag has the same sink, allows 63 characters of OID text instead of 62, and with WOLFSSL_NO_ASN_STRICT accepts any unrecognised critical extension, so non-strict 5.9.2 builds are exposed more broadly.
  • Fixed on master by commit 808be25236b3e151b6f3d0a5783fb19440235a6b (PR 11606). No release contains the fix.
  • A default ./configure build is not affected. Earlier releases were not checked.

Technical Details

Under WOLF_C89, XSNPRINTF(f, len, ...) expands to sprintf(f, __VA_ARGS__) (wolfssl/wolfcrypt/types.h:1235).

X509PrintExtensions() declares char scratch[MAX_WIDTH], 80 bytes (src/x509.c:7372), and resolves each extension's OID text into a second 80-byte buffer with wolfSSL_OBJ_obj2txt() (src/x509.c:7425). It then formats the header line (src/x509.c:7431-7441):

            if ((scratchLen = XSNPRINTF(
                     scratch, MAX_WIDTH, "%*s%s%s\n", indent + 4, "",
                     buf,
                     (wolfSSL_X509_EXTENSION_get_critical(ext)
                      ? ": critical"
                      : ": ")))
                >= MAX_WIDTH)
            {
                ret = WOLFSSL_FAILURE;
                break;
            }

When the object has no long name, wolfSSL_OBJ_obj2txt() falls back to wolfssl_obj2txt_numeric(), which produces at most 62 characters (src/ssl_asn1.c:5860-5871). wolfSSL_X509_print_ex() passes an indent of 8 (src/x509.c:8124). The line is then 12 spaces, 62 characters of OID text, the 10 characters of : critical, a newline and a NUL: 86 bytes into an 80-byte array. The six bytes past the end are the characters ical, the newline and the NUL. wolfSSL_X509_REQ_print() passes an indent of 4 (src/x509.c:8025), where the same text overruns by two bytes. A non-critical extension needs at most 78 bytes.

Whether a critical extension with long OID text gets this far depends on the parser:

  1. X509PrintExtensions() starts by calling wolfSSL_X509_get_ext_count() and prints nothing when it returns 0 (src/x509.c:7381-7383).
  2. wolfSSL_X509_get_ext_count() parses the certificate again and returns 0 when parsing fails (src/x509.c:151-159).
  3. An extension type the parser does not handle fails with ASN_CRIT_EXT_E when it is critical (wolfcrypt/src/asn.c:23038-23050), and ParseCertRelative() returns that error (wolfcrypt/src/asn.c:25944-25945). Such a certificate never reaches the formatting code.
  4. The parser does handle, and accepts as critical, the ACME identifier under WOLFSSL_ACME_OID (wolfcrypt/src/asn.c:23030-23037), the three dual-algorithm extensions under WOLFSSL_DUAL_ALG_CERTS (wolfcrypt/src/asn.c:23010-23029), and policyConstraints under WOLFSSL_NO_ASN_STRICT (wolfcrypt/src/asn.c:22983-22994). The compatibility layer has no name for any of them.
  5. The parser selects the extension type from a 32-bit identifier computed over the OID bytes (wolfcrypt/src/asn.c:7941-7969). It compares the OID bytes themselves only for types that have a reference OID (wolfcrypt/src/asn.c:8041-8080). These types have none (wolfcrypt/src/asn.c:6523-6592), so the OID that selects them is not required to be the registered one and its text can be long.
  6. wolfSSL_X509_set_ext() keeps the OID bytes and the critical flag from the certificate (src/x509.c:1076-1177), and the printer formats them.

Reachability and Preconditions

  • The library is built with WOLF_C89, the OpenSSL compatibility layer, and one of the three options listed above. None is a default.
  • The application prints an attacker-supplied certificate with wolfSSL_X509_print_ex() or wolfSSL_X509_print(), or a certificate request with wolfSSL_X509_REQ_print(). Parsing alone does not reach this code.
  • The certificate carries a critical extension that the parser accepts as one of the types in step 4 and whose OID text is 57 to 62 characters long. Its value must decode as that extension type.
  • No authentication is needed beyond delivering the certificate to the printing application.
  • In builds without one of the three options, a certificate with an unrecognised critical extension is rejected and is not printed.

Impact

Up to six bytes past an 80-byte stack buffer are overwritten. The bytes are fixed (ical, newline, NUL); the attacker controls how many are written, not their values. The print call then fails. What follows the buffer depends on the compiler; with stack protection the likely outcome is an abort of the process.

The path through steps 4 to 6 was established by reading the source. ByteRay did not build a proof of concept for this issue. The analysis is from source review. ByteRay does not claim code execution.

Remediation and Mitigation

Fixed on wolfSSL master by commit 808be25236b3e151b6f3d0a5783fb19440235a6b, merged in PR 11606. The fix formats only the indentation into the stack buffer, writes the OID text to the BIO directly, and then formats the fixed suffix. The fix is on master only; no release contains it as of 2026-12-03.

Until a release is available, integrators who need WOLF_C89 can apply that commit or provide a bounded XSNPRINTF of their own. Applications can also avoid printing certificates from untrusted sources.

Timeline

  • 2026-09-28 — Reported to wolfSSL.
  • 2026-09-30 — wolfSSL opened PR 11606.
  • 2026-10-19 — PR 11606 merged to master.
  • 2026-12-03 — Public disclosure.

Credits

Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd. wolfSSL credited ByteRay Ltd. for the reports in PR 11606.

References