]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: peers: trim received string keys to fit in a buffer
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 18 Nov 2026 10:02:39 +0000 (11:02 +0100)
committerOlivier Houchard <cognet@ci0.org>
Wed, 18 Nov 2026 15:33:22 +0000 (16:33 +0100)
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.

src/peers.c

index 3a4a1de21c2bb791d7246758bfdf26bacc4ffe71..bfff08468b6546ca3c853f1d50d02501ce4f653b 100644 (file)
@@ -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;