BUG/MINOR: tcpcheck: fix out-of-bounds reads on truncated SPOP hello frames
The SPOP health-check parser reads the frame header, then dispatches on the
frame type with a read right after the 11-byte header, and decodes the K/V
items of the payload. Nothing prevents these reads to go past the received
data:
- With a frame announcing no payload (flen == 0) and a received data
exactly covering the header, the frame type is read one byte past
the received data. It is fully deterministic and does not even
require the connection to be closed by the server.
- When a K/V item key name ends exactly at the end of the received
data, the type byte of the item value is read one byte past it.
- The frame length check may also overflow: it is computed as
4 + flen on a 32-bit value read from the wire, which wraps for a
length close to UINT32_MAX.
The bytes past the received data are stale buffer content: the parsing and
the check result are then driven by bytes never sent by the server.
The SPOP parser now validates the received data itself: a frame with no
payload is invalid (both the AGENT-HELLO and AGENT-DISCONNECT frames carry
at least one K/V item), the length comparison is made overflow-safe, and the
type byte of every K/V item value is only read when the payload is not fully
consumed. Truncated frames are reported as invalid instead of being parsed
from bytes never received.
It is a read past the received data, inside the check buffer, so it requires
a non-compliant agent, which is out of the threat model (servers are
trusted). There is no security impact, only a check status that depends on
stale data.
It should be backported to all supported versions.