← ALL ADVISORIES

LOW BYTERAY-2026-0419Patched

wolfSSL — Stack Out-of-Bounds Write in X.509 Serial Number Printing in WOLF_C89 Builds

In WOLF_C89 builds the certificate printer appends each serial number byte to an 80-byte stack buffer with an unbounded sprintf and checks the remaining space afterwards. Printing a certificate whose serial number is 23 to 32 bytes long writes three bytes past the buffer before the function returns an error.

Advisory
BYTERAY-2026-0419
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 OPENSSL_EXTRA
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

The OpenSSL compatibility layer prints certificates and certificate requests as text. X509PrintSerial_ex() builds the serial number line in an 80-byte stack buffer, one byte of the serial at a time, with XSNPRINTF, and tests after each write whether the output still fits. In a WOLF_C89 build XSNPRINTF is sprintf and ignores the size, so the test runs after the bytes are already on the stack.

wolfSSL accepts serial numbers of up to 32 bytes. With the indentation used for certificates, the 23rd byte of a serial starts at the last byte of the buffer and three bytes are written past it. The function then returns an error.

An attacker needs an application that prints a certificate the attacker supplied. The overrun is three bytes of fixed form. 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, X509PrintSerial_ex() and X509PrintSerial() in src/x509.c.
  • Required build: WOLF_C89 (--enable-c89, configure.ac:9024-9035, or the CMake option WOLFSSL_C89) and OPENSSL_EXTRA without NO_BIO (src/x509.c:6847-6848).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • The v5.9.2-stable and v5.9.4-stable tags contain the same function and the same macro mapping.
  • 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). The size argument is not used.

X509PrintSerial_ex() (src/x509.c:7220-7276) declares char scratch[MAX_WIDTH] with MAX_WIDTH equal to 80 (src/x509.c:6850-6852). For a serial longer than one byte it first writes a newline and indent + 4 spaces into the buffer (src/x509.c:7240-7245), then appends each byte (src/x509.c:7246-7258):

        for (i = 0; i < sz; i++) {
            int valLen;

            if ((valLen = XSNPRINTF(
                     scratch + scratchLen, scratchSz - scratchLen,
                     "%02x%s", serial[i], (i < sz - 1) ?
                     (delimiter ? ":" : "") : "\n"))
                >= scratchSz - scratchLen) {
                WOLFSSL_MSG("buffer overrun");
                return WOLFSSL_FAILURE;
            }
            scratchLen += valLen;
        }

Each iteration writes two hex digits, one delimiter or newline, and a terminating NUL. The comparison with the remaining space is evaluated on the value sprintf returns, after the write.

The arithmetic for the certificate path is:

  1. wolfSSL_X509_print_ex() calls X509PrintSerial() with an indent of 8 (src/x509.c:8089).
  2. X509PrintSerial() copies the serial into a 32-byte array and passes it on with the colon delimiter (src/x509.c:7278-7291).
  3. The prefix is 13 characters, so byte i of the serial is written at offset 13 + 3 * i.
  4. Byte 21 occupies offsets 76 to 78 and its NUL is at 79. That still fits.
  5. Byte 22 starts at offset 79. Its second hex digit, the delimiter and the NUL go to offsets 80, 81 and 82, which are past the end of scratch.
  6. The check then sees that 3 is not less than the 1 byte that was left and returns WOLFSSL_FAILURE.

The parser stores serial numbers of up to EXTERNAL_SERIAL_SIZE (32) bytes (wolfcrypt/src/asn.c:23542-23547), so a serial of 23 to 32 bytes reaches step 5. wolfSSL_X509_REQ_print() calls the same helper with the same indent (src/x509.c:8009), and the attribute certificate and CRL revoked-entry printers call X509PrintSerial_ex() directly (src/x509.c:8211, src/x509.c:9845). ByteRay did not establish which inputs give those callers a long enough serial, and this advisory makes no claim about them.

Reachability and Preconditions

  • The library is built with WOLF_C89 and the OpenSSL compatibility layer. Neither is a default.
  • The application prints an attacker-supplied certificate with wolfSSL_X509_print_ex(), or with wolfSSL_X509_print(), which calls it (src/x509.c:8140-8143). Parsing or verifying a certificate without printing it does not reach this code.
  • The certificate has a serial number of 23 to 32 bytes. RFC 5280 limits conforming serial numbers to 20 bytes, so certificates from ordinary certification authorities do not trigger it.
  • No authentication is needed beyond delivering the certificate to the printing application.

Impact

Three bytes past an 80-byte stack buffer are overwritten with one hexadecimal digit, a colon or newline, and a NUL. The attacker controls only the digit. What lies after the buffer depends on the compiler and its stack layout; with stack protection the likely outcome is an abort of the process. The print call fails either way.

ByteRay 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 808be25236b3e151b6f3d0a5783fb19440235a6b, merged in PR 11606. The fix formats each serial byte into a four-byte local buffer, writes the line to the BIO when the next byte would not fit, and then copies the byte. Long serial numbers are now printed in full instead of failing. 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