BUG/MINOR: tcpcheck: fix out-of-bounds read on the MySQL server version
On success, the MySQL health-check stores the server version, read at offset
5 of the received buffer, as the check description. The version is a
NUL-terminated string, but nothing guarantees the string is terminated,
neither inside the received data nor past its end. And the version pointer
is directly passed to set_server_check_status(), which copies it with
strncpy() up to 127 bytes, stopping at the first NUL byte. With a
non-compliant server sending a handshake with an unterminated version and no
NUL byte in the rest of the received data, the copy reads past the received
data, into the remaining content of the buffer chunk, and the stale bytes
are disclosed in the check status, visible in the logs, the stats page and
'show servers state'.
To fix it, the version is bounded to the received data before being copied
into the check status, like the plugin name of an auth switch request. This
is a rework of the out-of-bounds reads fixed by
3bbfc3bd7 ('BUG/MINOR:
tcpcheck: fix out-of-bounds reads on short MySQL error packets'), which
covered the error packets but not the success path.
This is a read past the received data, so it requires a non-compliant
server, which is out of the threat model (servers are trusted). Thus there
is no security impact here, only a potential information leak in the check
status.
This patch should fix the issue #3596. It should be backported to all
supported versions.