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.
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);