]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: payload: distcc_body must not sample unreceived buffer bytes master
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 20 Nov 2026 16:36:16 +0000 (17:36 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 20 Nov 2026 16:47:14 +0000 (17:47 +0100)
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.

src/payload.c

index ce87f76ff9ccc275a90b6959cf7db3565a6bcc51..9f75831176de2f50fb37754b499517dc20661986 100644 (file)
@@ -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);