← ALL ADVISORIES

LOW BYTERAY-2026-0446Disclosed

wolfSSL — One-Byte Heap Out-of-Bounds Read in ASN1_STRING_to_UTF8 with Time-Stamp Strings

wolfSSL_ASN1_STRING_to_UTF8 copies the string length plus one byte from the source, assuming a stored NUL terminator. Strings returned by the RFC 3161 time-stamp getters point into the raw response with no terminator, so the copy reads one byte past the response buffer and returns that byte to the application.

Advisory
BYTERAY-2026-0446
CWE
CWE-133
CVSS
3.7 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:N)
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 converts a time-stamp string with wolfSSL_ASN1_STRING_to_UTF8
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

wolfSSL_ASN1_STRING_to_UTF8() is an OpenSSL compatibility function that returns a copy of an ASN.1 string. It copies len + 1 bytes from the string's data. The extra byte is expected to be a NUL that wolfSSL stores after every string.

The RFC 3161 time-stamp compatibility layer does not store that NUL. wolfSSL_TS_STATUS_INFO_get0_text() and wolfSSL_TS_MSG_IMPRINT_get_msg() return string objects whose data pointer refers directly into the parsed response or the message imprint. When the status text is the last field of a time-stamp response, the byte after it is outside the heap buffer that holds the response.

An application that reads the status text of a response and converts it with this function reads one byte past that buffer and receives the byte in the returned copy. The layout of the response is chosen by the time-stamp server. 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_to_UTF8(). 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 the two functions; the application has to.
  • Other releases were not checked.

Technical Details

The copy is at src/ssl_asn1.c:2893-2901:

        /* Copy in string - NUL always put on end of stored string. */
        XMEMCPY(buf, data, (size_t)(len + 1));

The destination is len + 1 bytes and is large enough. The source is the problem: the function reads data[len]. wolfSSL_ASN1_STRING_set() does write a terminator there (src/ssl_asn1.c:3280-3282), but not every string is created through it. The only checks before the copy are that the data pointer is not NULL and the length is not negative (src/ssl_asn1.c:2882-2890).

How a string without a terminator reaches the copy:

  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. GetASN_GetConstRef() copies only the pointer and the size (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 fields that may follow the status text in a response are optional. A well-formed response can end with the text, and then data + len is the end of the heap buffer.
  5. wolfSSL_ASN1_STRING_to_UTF8() copies len + 1 bytes and reads one byte past the allocation.

wolfSSL_TS_MSG_IMPRINT_get_msg() builds a string of the same kind over the message imprint hash (src/ssl_tsp.c:442-455). The same missing terminator causes a longer over-read in the RFC 2253 print path, described in BYTERAY-2026-0371.

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 passes it to wolfSSL_ASN1_STRING_to_UTF8().
  • The attacker controls the time-stamp authority, or can alter its response in transit. The status text is outside the signed time-stamp token, so the token signature does not cover it.
  • 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

One byte of heap memory next to the response buffer is copied into the buffer returned to the application. What that byte contains depends on the heap layout. In a build with a memory checker the read is reported as a heap out-of-bounds read and the process stops. The read does not write to 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 in the copy itself: copy len bytes and write the terminator into the destination, which is what OpenSSL's function of the same name does. The allocation size is already correct. In addition, the two time-stamp getters can duplicate the bytes into owned, NUL-terminated storage so that they honour the convention other code relies on. Until then, an application can avoid the function for strings obtained from the time-stamp getters and copy the bytes itself using wolfSSL_ASN1_STRING_data() and wolfSSL_ASN1_STRING_length().

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