Bug #9066
closedlua/tls: SSLVersionToString buffer bound/return contract (latent 1-byte stack write at 20 bytes)
Description
- Status: present in
main(9b7938aec); latent (no 20-byte version exists today) - Class: latent 1-byte stack write / uninitialized read at the format-buffer boundary
- Component:
src/util-lua-tls.c:173-176,:321-325+rust/src/tls_version.rs:154-167
Description¶
Callers allocate char ssl_version[SSL_VERSION_MAX_STRLEN] (=20) and ignore the bool returned by SSLVersionToString:
char ssl_version[SSL_VERSION_MAX_STRLEN];
SSLVersionToString(connp->version, ssl_version);
lua_pushstring(luastate, ssl_version);
The Rust formatter returns false only when b.len() > 20 and otherwise writes b.len() bytes plus a terminating NUL at buf[b.len()] (rust/src/tls_version.rs:154-167), so a 20-byte version string would write buf[20] - one byte past the buffer. If it ever returns false, the caller reads the uninitialized buffer through strlen/lua_pushstring.
Not reachable today: the longest SCTlsVersion text is 19 bytes and unknown uint16_t values format as at most 5 decimal digits. Latent hardening.
Fix direction¶
Make the Rust bound >= len (or document len as excluding the NUL) and have the C callers handle false (fallback string / error).
Test¶
lua-tls-version-format: unit test over all uint16_t values including a synthetic 20-byte name under ASAN.