BUG/MINOR: tcpcheck: fix out-of-bounds reads on truncated LDAP bind responses
The LDAP health-check relies on the min-recv parameter of the expect rule
matching the first byte of the bind response to guarantee enough data are
received before parsing the message. But this parameter is only honored
while data are still expected: on a FIN or a connection error, the last read
is already reached and the rule is evaluated on the received data only. A
truncated response may thus be parsed with fewer bytes than the parser
assumes:
- With a single byte received, the message size is read one byte past
the received data.
- With a message announcing a size lower than 4, the 4-byte comparison
on the message ID and the bindResponse tag reads up to 3 bytes past
the received data.
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 LDAP parser now validates the received data itself: the message size
must be received, and the message must be at least 5 bytes to cover the
message ID, the bindResponse tag and its length. Shorter responses are
reported as truncated.
It is a read past the received data, inside the check buffer, so it requires
a non-compliant server, 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.