wolfSSL — Stack Buffer Overflow in CSR Attribute Printing on C89 Builds
On WOLF_C89 builds, XSNPRINTF expands to sprintf and ignores its size argument. X509PrintReqAttributes formats each CSR attribute value into an 80-byte stack buffer through that macro, so printing a request with a long attribute value writes past the buffer.
- Advisory
- BYTERAY-2026-0309
- 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 (tested at master commit d95483f), builds with WOLF_C89 (--enable-c89), WOLFSSL_CERT_REQ, WOLFSSL_CERT_GEN and OPENSSL_ALL where the application prints certificate signing requests
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
The OpenSSL compatibility layer can print a PKCS#10 certificate signing request with wolfSSL_X509_REQ_print(). For the attributes section it calls X509PrintReqAttributes(), which formats each attribute name and value into a fixed 80-byte stack buffer with XSNPRINTF.
On builds configured with --enable-c89, XSNPRINTF is defined as sprintf and the size argument is discarded. The attribute value comes from the request and, for most attribute types, is stored without a length cap. A value longer than the space left in the buffer is written past its end. The length check in the function compares the return value after the write has happened.
The result is a stack buffer overflow whose length and content are set by whoever wrote the request. A default ./configure build is not affected: there XSNPRINTF is snprintf and the output is truncated.
Affected Products and Versions
- Component:
src/x509.c,X509PrintReqAttributes(), reached fromwolfSSL_X509_REQ_print()in the OpenSSL compatibility layer. - Required build:
WOLF_C89, set by--enable-c89(configure.ac:9024-9035,CMakeLists.txt:3697-3704);WOLFSSL_CERT_REQfor the print function (src/x509.c:7918);OPENSSL_ALLandWOLFSSL_CERT_GENfor the code that copies request attributes onto the parsed object (src/internal.c:15207). - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild is not affected.--enable-c89is a documented, non-default option. - Other releases were not checked.
Technical Details
X509PrintReqAttributes() declares char scratch[MAX_WIDTH] (src/x509.c:7926). MAX_WIDTH is 80 (src/x509.c:6851). Each attribute is formatted into it (src/x509.c:7961-7964):
if ((scratchLen = XSNPRINTF(scratch, MAX_WIDTH,
"%*s%s%*s:%s\n", indent+4, "",
lName, (NAME_SZ/4)-lNameSz, "", data))
>= MAX_WIDTH)
Under WOLF_C89 the macro is #define XSNPRINTF(f, len, ...) sprintf(f, __VA_ARGS__) (wolfssl/wolfcrypt/types.h:1235). The MAX_WIDTH argument is dropped, so data is copied in full. The >= MAX_WIDTH comparison is evaluated on the return value, after sprintf has finished writing.
How the value reaches the buffer:
- The request parser records each attribute value as a pointer and length into the DER input, with the length taken from the encoding (
wolfcrypt/src/asn.c:25278-25328). CopyREQAttributes()(src/internal.c:15199) forwards those values towolfSSL_X509_REQ_add1_attr_by_NID()(src/x509.c:17421). Some of these calls are outside the length-checked copy blocks.wolfSSL_X509_REQ_add1_attr_by_NID()caps the length only for the challenge password (src/x509.c:17437) and the serial number (src/x509.c:17450). Other attribute types are stored at full length bywolfSSL_ASN1_STRING_set()(src/ssl_asn1.c:3264-3299).- The application calls
wolfSSL_X509_REQ_print()(src/x509.c:7983), which callsX509PrintReqAttributes()(src/x509.c:8030). - The value is formatted into
scratchby the unboundedsprintf.
The same macro behaviour is the cause of BYTERAY-2026-0308 (subjectAltName printing) and BYTERAY-2026-0310 (key identifier extension printing). Each is a separate buffer in a separate function.
Reachability and Preconditions
- Build:
WOLF_C89together withWOLFSSL_CERT_REQ,WOLFSSL_CERT_GENandOPENSSL_ALL. WithoutWOLF_C89the write is bounded. - Runtime: the application parses a certificate signing request it did not create and prints it with
wolfSSL_X509_REQ_print(). An enrollment or CA front end that logs or displays submitted requests fits this. - Attacker position: anyone who can submit a request to such a service. Submitting a request does not normally need credentials.
- Authentication state: none required. The print happens on the request as received.
- The API is used as documented. No unusual caller behaviour is needed.
Impact
A stack buffer overflow in the process that prints the request. The bytes written past the 80-byte buffer are the attribute value, so the submitter chooses both their content and how far the write extends.
A crash of the printing process is the reliable result. Because the overwritten region is the stack frame and the data is attacker-chosen, control-flow hijack is possible, subject to the stack protections of the target.
ByteRay reproduced this issue in an instrumented test build.
Remediation and Mitigation
ByteRay has not confirmed a fixed wolfSSL release for this issue as of 2026-12-03, and has not checked it against wolfSSL changes made after the tested commit.
The fix direction has three parts. The WOLF_C89 definition of XSNPRINTF should be a bounded formatter, or a build error where none is available, instead of sprintf. X509PrintReqAttributes() should check or truncate the value length before formatting; the existing comparison runs too late to help. The attribute copy and wolfSSL_X509_REQ_add1_attr_by_NID() should cap the length of every attribute type, as they already do for the challenge password and serial number.
Workarounds: build without --enable-c89 where the toolchain has snprintf, or supply a bounded XSNPRINTF binding for the C89 build. Applications on affected builds can avoid calling wolfSSL_X509_REQ_print() on requests from untrusted sources.
Timeline
- 2026-09-27 — Reported to wolfSSL.
- 2026-12-03 — Public disclosure.
Credits
Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.