wolfSSL — Stack Buffer Overflow in Key Identifier Extension Printing on C89 Builds
On WOLF_C89 builds, XSNPRINTF expands to sprintf and ignores its size argument. wolfSSL_X509V3_EXT_print formats the hex form of an Authority or Subject Key Identifier extension into a 129-byte stack buffer through that macro, so printing a certificate with a long key identifier writes past the buffer.
- Advisory
- BYTERAY-2026-0310
- 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) and the OpenSSL compatibility layer (OPENSSL_ALL or OPENSSL_EXTRA) where the application prints certificate extensions
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
wolfSSL_X509V3_EXT_print() is the OpenSSL compatibility function that writes a text form of a certificate extension to a BIO. For the Authority Key Identifier and Subject Key Identifier extensions it converts the extension value to a colon-separated hex string and formats that string into a 129-byte stack buffer with XSNPRINTF.
On builds configured with --enable-c89, XSNPRINTF is defined as sprintf and the size argument is discarded. The extension value is stored at whatever length the certificate gives it, and the hex form is about three times longer. When the hex string does not fit, sprintf writes past the end of the buffer. The only length handling in this case is a clamp applied after the write.
The result is a stack buffer overflow whose length is set by the certificate. A default ./configure build is not affected: there XSNPRINTF is snprintf and the output is truncated.
Affected Products and Versions
- Component:
src/x509.c,wolfSSL_X509V3_EXT_print(), theAUTH_KEY_OIDandSUBJ_KEY_OIDcases. - Required build:
WOLF_C89, set by--enable-c89(configure.ac:9024-9035,CMakeLists.txt:3697-3704), and the OpenSSL compatibility layer (OPENSSL_ALLorOPENSSL_EXTRA) so that the function is compiled in. - 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
The function declares char tmp[CTC_NAME_SIZE*2 + 1] (src/x509.c:1532). With CTC_NAME_SIZE at 64 the buffer is 129 bytes. The key identifier cases are (src/x509.c:1609-1622):
asn1str = wolfSSL_i2s_ASN1_STRING(NULL, str);
if (asn1str == NULL) {
WOLFSSL_MSG("wolfSSL_i2s_ASN1_STRING returned NULL");
return rc;
}
tmpLen = XSNPRINTF(tmp, tmpSz, "%*s%s", indent, "", asn1str);
XFREE(asn1str, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (tmpLen >= tmpSz)
tmpLen = tmpSz - 1;
Under WOLF_C89 the macro is #define XSNPRINTF(f, len, ...) sprintf(f, __VA_ARGS__) (wolfssl/wolfcrypt/types.h:1235). The tmpSz argument is dropped, so the whole hex string is copied. The clamp at src/x509.c:1620-1621 only limits the later BIO write. It runs after sprintf has returned.
How the value reaches the buffer:
- The certificate carries an Authority Key Identifier or Subject Key Identifier extension. Its value length is taken from the encoding.
- When the extension object is built, the value is stored in full by
wolfSSL_ASN1_STRING_set()(src/x509.c:950), which allocates for any size and keeps the length (src/ssl_asn1.c:3264-3299). - The application calls
wolfSSL_X509V3_EXT_print()(src/x509.c:1525). The extension data is fetched atsrc/x509.c:1551. - For the key identifier cases,
wolfSSL_i2s_ASN1_STRING()returns a heap string of3*length - 1characters (src/ssl_asn1.c:2921-2952,src/ssl_asn1.c:2963-2988). - That string is formatted into
tmpby the unboundedsprintf(src/x509.c:1618).
The subject alternative name case in the same function checks the required length against tmpSz before it formats (src/x509.c:1583-1586). The key identifier case has no such check.
The same macro behaviour is the cause of BYTERAY-2026-0308 (subjectAltName printing) and BYTERAY-2026-0309 (CSR attribute printing). Each is a separate buffer in a separate function.
Reachability and Preconditions
- Build:
WOLF_C89together withOPENSSL_ALLorOPENSSL_EXTRA. WithoutWOLF_C89the write is bounded. - Runtime: the application calls
wolfSSL_X509V3_EXT_print()on a key identifier extension of a certificate it received from another party, for example to log or display a peer certificate. - Attacker position: a TLS peer, or anyone else who can hand the application a certificate that it later prints.
- Authentication state: none required. The certificate does not have to pass verification to be parsed and printed.
- The API is used as documented. No unusual caller behaviour is needed.
Impact
A stack buffer overflow in the process that prints the extension. The bytes written past the 129-byte buffer are hex digits and colons derived from the extension value. The certificate sets the value and its length, and so how far the write extends.
A crash of the printing process is the reliable result. Because the overwritten region is the stack frame, control-flow hijack is possible, subject to the stack protections of the target and the restricted character set of the written data.
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 is to compute the required size before formatting in the key identifier case, as the subject alternative name case already does, and to fail, truncate or allocate when it exceeds tmpSz. The WOLF_C89 definition of XSNPRINTF should be a bounded formatter, or a build error where none is available, instead of sprintf. Capping the stored extension value length at parse time adds a second layer.
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_X509V3_EXT_print() on certificates 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.