From: Christopher Faulet Date: Fri, 20 Nov 2026 16:36:16 +0000 (+0100) Subject: BUG/MINOR: payload: distcc_body must not sample unreceived buffer bytes X-Git-Url: https://git.kaiwu.me/web/%22data:,//%22%22?a=commitdiff_plain;ds=inline;p=haproxy.git BUG/MINOR: payload: distcc_body must not sample unreceived buffer bytes When the declared body of a distcc token is longer than the data actually received but still fits within the channel's receive limit, smp_fetch_distcc_body() truncates the sample to channel_recv_limit() instead of ci_data(). The sample then covers a range of the buffer that has not been filled by the current connection, exposing stale bytes left by a previous connection using the same pooled buffer, e.g. via ACLs, set-var, log-format or header insertion. In addition, the incomplete-body check mixed reference frames: ofs is relative to the input head, but was compared against ci_head() - b_orig() + ci_data(), which is only equivalent when the input head sits at the buffer origin. With bytes already forwarded, a body extending past the received data could be considered complete. Both issues are fixed by comparing and truncating against ci_data(), the amount of input data actually received, and by always setting SMP_F_MAY_CHANGE on truncated bodies so the rules are re-evaluated once more data arrives. This patch should fix the issue #3583. It must be backported to all supported versions. --- diff --git a/src/payload.c b/src/payload.c index ce87f76ff..9f7583117 100644 --- a/src/payload.c +++ b/src/payload.c @@ -1432,14 +1432,10 @@ smp_fetch_distcc_body(const struct arg *arg_p, struct sample *smp, const char *k smp->data.type = SMP_T_BIN; smp->flags = SMP_F_VOLATILE | SMP_F_CONST; - if (ofs + body > ci_head(chn) - b_orig(&chn->buf) + ci_data(chn)) { + if (ofs + body > ci_data(chn)) { /* incomplete body */ - - if (ofs + body > channel_recv_limit(chn) + b_orig(&chn->buf) - ci_head(chn)) { - /* truncate it to whatever will fit */ - smp->flags |= SMP_F_MAY_CHANGE; - body = channel_recv_limit(chn) + b_orig(&chn->buf) - ci_head(chn) - ofs; - } + smp->flags |= SMP_F_MAY_CHANGE; + body = ci_data(chn) - ofs; } chunk_initlen(&smp->data.u.str, ci_head(chn) + ofs, 0, body);