← ALL ADVISORIES

LOW BYTERAY-2026-0417Patched

wolfSSL — Out-of-Bounds Write in Certificate Policy OID Text Decoding in WOLF_C89 Builds

In WOLF_C89 builds DecodePolicyOID converts each OID arc to text with an unbounded sprintf and checks the length afterwards. A certificate whose certificatePolicies OID is longer than the 200-byte destination writes up to 11 bytes past it inside the decoded certificate structure while the certificate is parsed, before the certificate is rejected.

Advisory
BYTERAY-2026-0417
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) and WOLFSSL_CERT_EXT
Fixed in
Master commit c991775457c96c1b9a04eb2dc064672790356c39 (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

DecodePolicyOID() turns the DER encoding of an object identifier into dotted-decimal text. It writes each arc with XSNPRINTF and compares the returned length with the space that was left. That order is safe when XSNPRINTF is a real snprintf. In a WOLF_C89 build the macro expands to sprintf and the size argument is dropped, so the arc is written in full and the check runs after the write.

The certificate parser calls this function for every policy in a certificatePolicies extension, with a 200-byte row of the DecodedCert structure as the destination. A policy OID of at most 127 encoded bytes can produce more than 200 characters. The last arc written can extend 11 bytes past the row before the function reports an error and the certificate is rejected.

The write happens during parsing, before any signature is verified, so the certificate can come from a TLS peer. Default builds are not affected: WOLF_C89 and WOLFSSL_CERT_EXT are both off by default. This is one instance of the macro behaviour described in BYTERAY-2026-0339.

Affected Products and Versions

  • Component: wolfCrypt ASN.1 certificate parsing, DecodePolicyOID() and DecodeCertPolicy() in wolfcrypt/src/asn.c.
  • Required build: WOLF_C89 (--enable-c89, configure.ac:9024-9035, or the CMake option WOLFSSL_C89) together with WOLFSSL_CERT_EXT (--enable-certext, configure.ac:5734-5743; --enable-all-crypto and several application compatibility options also turn it on).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • The v5.9.2-stable and v5.9.4-stable tags contain the same function, the same macro mapping and the same caller.
  • Fixed on master by commit c991775457c96c1b9a04eb2dc064672790356c39 (PR 11606). No release contains the fix.
  • A default ./configure build is not affected. Earlier releases were not checked.

Technical Details

Under WOLF_C89 the bounded formatting macro is defined without its bound (wolfssl/wolfcrypt/types.h:1235):

                    #define XSNPRINTF(f, len, ...) sprintf(f, __VA_ARGS__)

DecodePolicyOID() (wolfcrypt/src/asn.c:22186-22242) rejects inputs of 128 bytes or more (wolfcrypt/src/asn.c:22194), writes the first two arcs (wolfcrypt/src/asn.c:22200), then loops while there is input and outIdx < outSz (wolfcrypt/src/asn.c:22208). Each completed arc is written and then checked (wolfcrypt/src/asn.c:22222-22228):

            val += in[inIdx];
            w = XSNPRINTF(out + outIdx, outSz - outIdx, ".%u", val);
            if (w < 0 || (word32)w > outSz - outIdx) {
                w = BUFFER_E;
                goto exit;
            }
            outIdx += (word32)w;

val is a 32-bit value built from up to five input bytes, so one arc is a dot and up to ten digits. With sprintf the eleven characters and the terminating NUL are written wherever out + outIdx points. The loop condition allows outIdx to be as high as outSz - 1, so the write can cover out[outSz - 1] through out[outSz + 10]: 11 bytes past the buffer. Only then does the check return BUFFER_E. If the text fills the buffer exactly, the check passes and the NUL alone lands at out[outSz].

The parse-time data flow is:

  1. DecodeExtensionType() dispatches a certificatePolicies extension to DecodeCertPolicy() (wolfcrypt/src/asn.c:22880-22892).
  2. DecodeCertPolicy() walks the policies while fewer than MAX_CERTPOL_NB (2) are stored (wolfcrypt/src/asn.c:22306-22310).
  3. For each policy it calls DecodePolicyOID() on cert->extCertPolicies[cert->extCertPoliciesNb] with MAX_CERTPOL_SZ (200) as the size (wolfcrypt/src/asn.c:22347-22349).
  4. On error it sets ASN_PARSE_E (wolfcrypt/src/asn.c:22350-22352) and the certificate is rejected.

The destination is a two-row array inside DecodedCert, followed directly by the policy counter and other fields (wolfssl/wolfcrypt/asn.h:2124-2128). An overrun of the first row lands in the second row. An overrun of the second row lands in extCertPoliciesNb, nsCertType and whatever the compiler places after them.

DecodePolicyOID() has a second caller. wolfSSL_OBJ_obj2txt() reaches it through wolfssl_obj2txt_numeric() with a size of at most 63 (src/ssl_asn1.c:5860-5871). In a WOLF_C89 build the same late check lets it write up to index 73 of the caller's buffer, which is 10 bytes past a 64-byte buffer.

Reachability and Preconditions

  • The library is built with WOLF_C89 and WOLFSSL_CERT_EXT. Neither is a default.
  • The attacker supplies a certificate that the application parses: a TLS peer certificate in either direction, or a certificate loaded from an untrusted file or message.
  • No authentication is needed. Extensions are decoded before the signature is checked, so the certificate does not have to chain to a trusted root.
  • No user interaction is needed.
  • The overrun is limited to 11 bytes per policy and the bytes written are decimal digits, a dot and a NUL.

Impact

Up to 11 bytes of the decoded-certificate structure after the policy array are overwritten with digit characters while a certificate is parsed. In the case that reaches past the array the parser then returns an error and the certificate is rejected. The confirmed effect is corruption of fields in a structure that is about to be discarded; depending on where the build places that structure and what follows the array, this can also end the process.

ByteRay did not find a way to choose the overwritten bytes beyond digits, or to extend the write past 11 bytes, and does not claim code execution. ByteRay did not build a proof of concept for this issue. The analysis is from source review.

Remediation and Mitigation

Fixed on wolfSSL master by commit c991775457c96c1b9a04eb2dc064672790356c39, merged in PR 11606. The fix formats each arc into a small local buffer and copies it into the output only when it fits, so the result no longer depends on XSNPRINTF honouring its size argument. 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 supply their own bounded XSNPRINTF definition before wolfssl/wolfcrypt/types.h selects the sprintf mapping. Building without WOLF_C89 removes the issue.

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