← ALL ADVISORIES

MEDIUM BYTERAY-2026-0371Disclosed

wolfSSL — Heap Over-Read in RFC 2253 ASN.1 String Printing with Time-Stamp Strings

The RFC 2253 escaping branch of wolfSSL_ASN1_STRING_print_ex finds the end of a string by scanning for a NUL byte and ignores the stored length. Strings returned by the RFC 3161 time-stamp getters have no terminator, so printing one reads past the response buffer and writes the bytes it passes to the output BIO.

Advisory
BYTERAY-2026-0371
CWE
CWE-133
CVSS
4.8 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:L)
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-28
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 (tested at master commit d95483f), builds with OPENSSL_EXTRA and time-stamp support (WOLFSSL_TSP, HAVE_PKCS7, WOLFSSL_TSP_VERIFIER) where the application prints a time-stamp string with ASN1_STRING_print_ex and the ESC_2253 or RFC2253 flag
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

wolfSSL_ASN1_STRING_print_ex() prints an ASN.1 string to a BIO. When the flags include ASN1_STRFLGS_ESC_2253, it calls a helper that walks the string one byte at a time until it finds a NUL. The helper does not look at the string's length.

Most strings in wolfSSL carry a NUL after their data. Strings from the RFC 3161 time-stamp compatibility layer do not: wolfSSL_TS_STATUS_INFO_get0_text() and wolfSSL_TS_MSG_IMPRINT_get_msg() return objects that point directly into the parsed response or the message imprint.

An application that prints the status text of a time-stamp response this way reads past the end of the heap buffer holding the response. Every byte passed is written to the output BIO until a zero byte turns up. Adjacent heap contents end up in the application's output, and the process can crash if the scan reaches unmapped memory. Time-stamp support and the OpenSSL compatibility layer are not part of a default build.

Affected Products and Versions

  • Component: src/ssl_asn1.c, wolfssl_asn1_string_print_esc_2253(), reached from the public wolfSSL_ASN1_STRING_print_ex(). The strings that trigger it come from src/ssl_tsp.c.
  • Required build: OPENSSL_EXTRA with WOLFSSL_TSP, HAVE_PKCS7 and WOLFSSL_TSP_VERIFIER (src/ssl_tsp.c:32-33).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default build is not affected. Time-stamp support is disabled by default (configure.ac:9599-9601). No caller inside wolfSSL combines these functions; the application has to.
  • Other releases were not checked.

Technical Details

The helper is at src/ssl_asn1.c:3639-3667. Its loop is:

    for (p = str->data; (*p) != '\0'; p++) {

Inside the loop each byte is written with wolfSSL_BIO_write(), preceded by a backslash when it needs escaping (src/ssl_asn1.c:3648-3663). str->length is never read.

wolfSSL_ASN1_STRING_print_ex() selects this helper when the flags contain WOLFSSL_ASN1_STRFLGS_ESC_2253 (src/ssl_asn1.c:3706-3708). That flag has the value 1 (wolfssl/ssl.h:369) and is part of the composite WOLFSSL_ASN1_STRFLGS_RFC2253 (wolfssl/ssl.h:379), so both select the same branch. The other print routines in the same file are bounded by the string length.

How a string without a terminator reaches the loop:

  1. wolfSSL_d2i_TS_RESP() copies the time-stamp response into a heap buffer of exactly the response size (src/ssl_tsp.c:1377-1383) and decodes it in place (src/ssl_tsp.c:1385).
  2. The decoder records the status text as a pointer and length into that buffer, without copying (wolfcrypt/src/asn_tsp.c:870-875, wolfcrypt/src/asn.c:2482-2486).
  3. wolfSSL_TS_STATUS_INFO_get0_text() wraps that pointer in a WOLFSSL_ASN1_STRING with isDynamic = 0 (src/ssl_tsp.c:883-890).
  4. The response fields after the status text are optional. When the text is the last field and contains no zero byte, its end is the end of the heap buffer.
  5. The application calls wolfSSL_ASN1_STRING_print_ex() with the RFC 2253 escaping flag. The loop continues past the buffer and writes what it reads to the BIO.

wolfSSL_TS_MSG_IMPRINT_get_msg() produces a string of the same kind over the message imprint hash (src/ssl_tsp.c:442-455). The same missing terminator causes a one-byte over-read in wolfSSL_ASN1_STRING_to_UTF8(), described in BYTERAY-2026-0446. Here the read has no fixed bound.

Reachability and Preconditions

  • Build with OPENSSL_EXTRA and the time-stamp options above.
  • The application parses a time-stamp response from a remote time-stamp authority, obtains the status text with wolfSSL_TS_STATUS_INFO_get0_text() and prints it with ASN1_STRING_print_ex() using ASN1_STRFLGS_ESC_2253 or ASN1_STRFLGS_RFC2253.
  • The attacker controls the time-stamp authority, or can alter its response in transit. The status text is outside the signed time-stamp token.
  • The response is arranged so that the status text ends at the last byte of the message.
  • No authentication is required beyond being the party that answers the request.

Impact

Heap bytes that follow the response buffer are written to the application's output BIO, up to the next zero byte. They can include pointers or other data allocated nearby. The bytes go to wherever the application sends that output, not directly back to the attacker. If the scan reaches an unmapped page the process crashes. Nothing is written to the over-read memory.

ByteRay did not build a proof of concept for this issue. The analysis is from source review.

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 for the helper to iterate over exactly str->length bytes and stop. More generally, string data in the compatibility layer should be treated as length-delimited, because not every producer stores a terminator. In addition, the two time-stamp getters can duplicate the bytes into owned, NUL-terminated storage. Until then, an application can print strings obtained from the time-stamp getters with wolfSSL_ASN1_STRING_print(), which is bounded by the length, or with ASN1_STRING_print_ex() without the RFC 2253 escaping flag.

Timeline

  • 2026-09-28 — Reported to wolfSSL.
  • 2026-12-03 — Public disclosure.

Credits

Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.

References