wolfSSL — Unbounded sprintf Behind the XSNPRINTF Macro in WOLF_C89 Builds
In WOLF_C89 builds the XSNPRINTF macro expands to sprintf and discards its size argument. Callers across the library format untrusted data into fixed buffers and rely on that size, or on a length check made after the write, so certificate fields can overflow stack and structure buffers. Master has bounded the known call sites but keeps the mapping.
- Advisory
- BYTERAY-2026-0339
- CWE
- CWE-1177
- CVSS
- 5.6 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/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)
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
wolfSSL formats text through the portability macro XSNPRINTF(buffer, size, format, ...). On most platforms it is snprintf. When the library is built for a C89 toolchain with WOLF_C89, the macro is defined as sprintf(buffer, format, ...): the size is accepted and thrown away. XSPRINTF is sprintf as well.
Library code is written as if the macro were bounded. The common pattern is to format into a fixed buffer and then compare the returned length with the buffer size. With sprintf that comparison happens after the write. Where the formatted data comes from a certificate, a peer can overflow the buffer. At the tested commit this includes subject alternative names of any length printed into an 80-byte stack buffer.
Default builds are not affected; WOLF_C89 must be requested. wolfSSL has since bounded the call sites it identified, but the macro still maps to sprintf on master, so any other or future call site is unbounded in these builds.
Affected Products and Versions
- Component:
wolfssl/wolfcrypt/types.h, theWOLF_C89definitions ofXSNPRINTFandXSPRINTF, and every caller of those macros. - Required build:
WOLF_C89, set by--enable-c89(configure.ac:9024-9035) or the CMake optionWOLFSSL_C89(CMakeLists.txt:3697-3704), without a user-suppliedXSNPRINTF. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- The
v5.9.2-stableandv5.9.4-stabletags contain the same mapping. - Not fixed on master: the mapping is unchanged. The call sites named in this advisory have been bounded on master; no release contains those changes.
- A default
./configurebuild is not affected. Earlier releases were not checked.
Technical Details
The mapping is in the WOLF_C89 branch of the XSNPRINTF selection (wolfssl/wolfcrypt/types.h:1225-1236):
#elif defined(WOLF_C89)
#ifndef NO_STDIO_FILESYSTEM
#include <stdio.h>
#endif
#define XSPRINTF sprintf
/* snprintf not available for C89, so remap using macro */
#ifdef WOLF_NO_VARIADIC_MACROS
#error WOLF_NO_VARIADIC_MACROS requires user-supplied \
binding for XSNPRINTF
#else
#define XSNPRINTF(f, len, ...) sprintf(f, __VA_ARGS__)
#endif
len does not appear in the expansion. The default for XSPRINTF outside this branch is also sprintf (wolfssl/wolfcrypt/wc_port.h:1640-1642). At the tested commit the two macros are used on about 170 source lines under src/ and wolfcrypt/src/.
The subject alternative name printer shows the effect. X509_print_name_entry() formats each name into char scratch[MAX_WIDTH], 80 bytes (src/x509.c:6978):
if (entry->type == ASN_DNS_TYPE) {
len = XSNPRINTF(scratch, MAX_WIDTH, "DNS:%s", entry->name);
}
The email and URI branches do the same (src/x509.c:7021-7022, src/x509.c:7034-7035). The length is tested only after all branches (src/x509.c:7060). The data flow is:
- The certificate parser stores each alternative name at its full length.
X509PrintSubjAltName()passes the list toX509_print_name_entry()(src/x509.c:7357-7362) when an application prints the certificate.- In a
WOLF_C89buildsprintfcopies the whole name intoscratch(src/x509.c:7004). A name longer than 75 characters runs past the buffer by its excess length. - The check at
src/x509.c:7060returns failure after the stack has been overwritten.
Two smaller instances are described separately: policy OID text written during certificate parsing (BYTERAY-2026-0417) and the serial number line of the certificate printer (BYTERAY-2026-0419). BYTERAY-2026-0418 covers the extension header line of the same printer.
Reachability and Preconditions
- The library is built with
WOLF_C89. This is off by default and intended for compilers without C99 library support. - The integrator has not supplied a bounded
XSNPRINTF. The selection is inside#ifndef XSNPRINTF(wolfssl/wolfcrypt/types.h:1191), so a definition made earlier takes precedence. - A call site formats attacker-influenced data into a fixed buffer. The parse-time instance needs only that a certificate is parsed, with
WOLFSSL_CERT_EXT. The printing instances needOPENSSL_EXTRAand an application that prints certificates it did not create. - No authentication is needed to present a certificate to a TLS endpoint.
Impact
For the subject alternative name printer, the amount written past the 80-byte stack buffer is the length of the name, which the certificate's author chooses. This is a stack buffer overflow with attacker-influenced content in a non-default build, and it is the basis for the confidentiality, integrity and availability components of the rating. The other verified instances are limited to 11 bytes or fewer of constrained content.
ByteRay did not audit every use of the macros and does not claim that each one is reachable with untrusted data. ByteRay did not build a proof of concept for this issue. The analysis is from source review.
Remediation and Mitigation
Not fixed on wolfSSL master as of commit e4b0841b32e7 (2026-12-03). The macro definitions are unchanged. wolfSSL chose to bound the call sites instead: PR 11606 states that the mapping stays and changes DecodePolicyOID(), the registered-ID alternative name formatter, the serial number, extension and key identifier printers, the key number printer, and the error-message and time-string formatting; PR 11682 rewrote the alternative name printer so that names are written to the BIO rather than into the stack buffer. Both are on master only. On master the macros are still used on about as many lines as before, and each use remains unbounded in a WOLF_C89 build.
A complete fix removes the mapping: either provide a bounded formatter for C89 builds or make WOLF_C89 require a user-supplied XSNPRINTF, as WOLF_NO_VARIADIC_MACROS already does. Integrators can do the second today by defining XSNPRINTF to a bounded function from their platform before including wolfSSL headers. The cost is supplying and testing that function on a toolchain that lacks snprintf.
Timeline
- 2026-09-28 — Reported to wolfSSL.
- 2026-09-30 — wolfSSL opened PR 11606.
- 2026-10-07 — wolfSSL opened PR 11682.
- 2026-10-15 — PR 11682 merged to master.
- 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, which bounds several of the affected call sites.
References
- WOLF_C89 definitions of XSNPRINTF and XSPRINTF at the tested commit
- X509_print_name_entry at the tested commit
- wolfSSL pull request 11606
- wolfSSL pull request 11682
- BYTERAY-2026-0417: certificate policy OID text decoding
- BYTERAY-2026-0418: X.509 extension line printing
- BYTERAY-2026-0419: X.509 serial number printing
- CWE-1177: Use of Prohibited Code