]> git.kaiwu.me - haproxy.git/commit
BUG/MEDIUM: peers: bound stick-table switch messages
authorFrederic Lecaille <flecaille@haproxy.com>
Wed, 18 Nov 2026 14:03:37 +0000 (15:03 +0100)
committerFrederic Lecaille <flecaille@haproxy.com>
Wed, 18 Nov 2026 14:53:46 +0000 (15:53 +0100)
commit67392268bf6fe1d04d93dbe1f15c81bd9cb6b08e
tree7d6b9bddc0040c76ad06c4ee3b8a03a8aaf97863
parentef4405d67417f9aac967520122d1fdb597700e15
BUG/MEDIUM: peers: bound stick-table switch messages

peer_prepare_switchmsg() builds the table definition message in the
<size>-byte trash buffer but, like its update counterpart before commit
8e0f311ff, never checked that the encoded data fit. The table name was
copied with a plain memcpy() following an intencode() of its length, and
all other fields were encoded with intencode(), which cannot fail.

Unlike the update message, this one is mostly made of a variable-length
field, the table name: the peers section name, a '/', and the table name,
which gives a nid as large as the configuration line allows. The rest is
a fixed 33-byte overhead plus the data type parameters. Nothing accounts
for that name when validating the stick-table at configuration time, so
a table whose name is close to tune.bufsize is accepted and its copy runs
past the end of the trash buffer when the peer sessions start.

Let's check the room left before every copy and every varint encoding,
using the same peer_bufcpy() helper and the same single-exit error
convention as for the update message. The data type parameters are
staged in a trash chunk, not in <msg>, so their encoding is bounded by
the chunk itself through a distinct chunk_end pointer, while the varints
written to <msg>, the bitfield and the expiration are bounded by the
message end.

The payload length becomes a size_t for consistency with the update
message, though the definition message is inherently small.

Thank you to @h110hawk for having reported this issue in GH #3576.

This should be backported to all supported versions.
src/peers.c