From: Olivier Houchard Date: Wed, 18 Nov 2026 10:02:39 +0000 (+0100) Subject: BUG/MEDIUM: peers: trim received string keys to fit in a buffer X-Git-Tag: v3.5-dev13~1 X-Git-Url: https://git.kaiwu.me/web/%22data:,/doc/static/%7B@url%7D?a=commitdiff_plain;h=acc8202ebf83c11a6d90320154c6a37b9d65bde1;p=haproxy.git BUG/MEDIUM: peers: trim received string keys to fit in a buffer Commit b224f63c1 ("BUG/MEDIUM: stick-table: restrict key sizes to what fits in a buffer") trims string keys in stksess_setkey() so that the update message fits in a buffer, but string keys received from a peer are copied directly and only bounded by the table's key size. A peer with a larger bufsize, or a forged message, can thus store a key which cannot be encoded when it is later taught to another peer. Since commit ef4405d67 ("BUG/MEDIUM: peers: bound stick-table update messages") this does not overflow the trash buffer anymore, but the peer session is closed and reopened in loop and the resync never completes, as reported in GitHub issue #3576. Let's apply the same trimming on the receive path. This must be backported wherever b224f63c1 was. --- diff --git a/src/peers.c b/src/peers.c index 3a4a1de21..bfff08468 100644 --- a/src/peers.c +++ b/src/peers.c @@ -1941,6 +1941,8 @@ int peer_treat_updatemsg(struct appctx *appctx, struct peer *p, int updt, int ex } to_store = MIN(to_read, table->key_size - 1); + if (to_store + table->proto_size > global.tune.bufsize) + to_store = global.tune.bufsize - table->proto_size; if (*msg_cur + to_store > msg_end) { TRACE_ERROR("malformed update message: invalid string (too big)", PEERS_EV_SESS_IO|PEERS_EV_RX_MSG|PEERS_EV_PROTO_ERR, appctx, p, st); goto malformed_free_newts;