From: Frederic Lecaille Date: Wed, 18 Nov 2026 14:17:28 +0000 (+0100) Subject: BUG/MINOR: peers: bound stick-table acknowledge messages X-Git-Tag: v3.5-dev13~6 X-Git-Url: https://git.kaiwu.me/web/%22data:,/doc/static/%7B@url%7D?a=commitdiff_plain;h=96aab75ba6e6c5194b3a29e7b6fd33712e1aafd5;p=haproxy.git BUG/MINOR: peers: bound stick-table acknowledge messages peer_prepare_ackmsg() was the last message builder of the peers code still encoding without knowing the buffer end: lengths went through intencode(), which cannot fail, and the last acknowledged update counter was copied with a plain memcpy(). Its payload is a bounded varint plus a 32-bit counter, i.e. 9 bytes at most, so it could not overflow. The bounds are added anyway, for consistency with the update and switch message builders, and they make intencode() unused: being defined without any prototype in a header, the compiler cannot report it as unused, so it is removed here along with its comment, otherwise it would have stayed in the binary silently. Must be backported to all stable versions. --- diff --git a/src/peers.c b/src/peers.c index 940a56df0..6d9412533 100644 --- a/src/peers.c +++ b/src/peers.c @@ -1120,23 +1120,28 @@ static int peer_prepare_switchmsg(char *msg, size_t size, struct peer_prep_param * This prepare the acknowledge message on the stick session , is the considered * stick table. * is a buffer of to receive data message content - * If function returns 0, the caller should consider we were unable to encode this message (TODO: - * check size) + * If function returns 0, the caller should consider we were unable to encode this message. */ static int peer_prepare_ackmsg(char *msg, size_t size, struct peer_prep_params *p) { unsigned short datalen; - char *cursor, *datamsg; + char *cursor, *datamsg, *end; uint32_t netinteger; struct shared_table *st; + if (size < PEER_MSG_HEADER_LEN + PEER_MSG_ENC_LENGTH_MAXLEN) + return 0; + cursor = datamsg = msg + PEER_MSG_HEADER_LEN + PEER_MSG_ENC_LENGTH_MAXLEN; + end = msg + size; st = p->ack.shared_table; - intencode(st->remote_id, &cursor); + if (encode_varint(st->remote_id, &cursor, end) == -1) + return 0; + netinteger = htonl(st->last_get); - memcpy(cursor, &netinteger, sizeof(netinteger)); - cursor += sizeof(netinteger); + if (peer_bufcpy(&cursor, end, &netinteger, sizeof(netinteger)) == 0) + return 0; /* Compute datalen */ datalen = (cursor - datamsg); @@ -1145,7 +1150,8 @@ static int peer_prepare_ackmsg(char *msg, size_t size, struct peer_prep_params * msg[0] = PEER_MSG_CLASS_STICKTABLE; msg[1] = PEER_MSG_STKT_ACK; cursor = &msg[2]; - intencode(datalen, &cursor); + if (encode_varint(datalen, &cursor, end) == -1) + return 0; /* move data after header */ memmove(cursor, datamsg, datalen);