From: Christopher Faulet Date: Thu, 3 Dec 2026 17:05:26 +0000 (+0100) Subject: BUG/MINOR: htx: only rollback blocks copied by the current call in htx_xfer() X-Git-Url: https://git.kaiwu.me/web/http/static//%22?a=commitdiff_plain;h=bd69dcf068fd2fe384d74efbf43f640cc697ffcf;p=haproxy.git BUG/MINOR: htx: only rollback blocks copied by the current call in htx_xfer() When partial copies of headers or trailers are not allowed, htx_xfer() removes the start-line, header and trailer blocks found at the end of when the copy is interrupted, and rolls back on accordingly. But this was not limited to the blocks copied by the current call. If already ended with such blocks, for instance a trailer block added by the cache applet, these blocks were removed too, and the rollback on went beyond its first block. In this case, was then fully drained. Now, the start-line, header and trailer blocks copied at the end of are counted, and only these blocks are removed on rollback. This patch must be backported to 3.4. --- diff --git a/src/htx.c b/src/htx.c index bda321397..6e6e41244 100644 --- a/src/htx.c +++ b/src/htx.c @@ -871,6 +871,7 @@ size_t htx_xfer(struct htx *dst, struct htx *src, size_t count, unsigned int fla size_t ret = 0; size_t meta_sz = (flags & HTX_XFER_NO_METADATA) ? 0 : sizeof(*blk); uint32_t max, last_dstblk_sz; + uint32_t nb_hdrs = 0; int dst_full = 0; /* Note: no test on the end of the message here. Blocks are added one by @@ -914,6 +915,7 @@ size_t htx_xfer(struct htx *dst, struct htx *src, size_t count, unsigned int fla last_dstblk_sz = v.len; count -= meta_sz + v.len; ret += meta_sz + v.len; + nb_hdrs = 0; if (v.len != sz) { dst_full = 1; goto stop; @@ -938,6 +940,15 @@ size_t htx_xfer(struct htx *dst, struct htx *src, size_t count, unsigned int fla last_dstblk_sz = sz; count -= meta_sz + sz; ret += meta_sz + sz; + + /* Count the start-line, header and trailer blocks + * copied at the end of by this call. Only these + * ones may be removed if the copy is interrupted. + */ + if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL || type == HTX_BLK_HDR || type == HTX_BLK_TLR) + nb_hdrs++; + else + nb_hdrs = 0; break; } @@ -961,15 +972,22 @@ size_t htx_xfer(struct htx *dst, struct htx *src, size_t count, unsigned int fla if (dstblk) type = htx_get_blk_type(dstblk); - /* the last copied block is a start-line, a header or a trailer */ - if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL || type == HTX_BLK_HDR || type == HTX_BLK_TLR) { + /* the last copied block is a start-line, a header or a + * trailer. Blocks already present in before this call + * must not be considered. + */ + if (nb_hdrs && (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL || type == HTX_BLK_HDR || type == HTX_BLK_TLR)) { /* cannot have partial headers or trailers part */ BUG_ON(blk == NULL); - /* Remove partial headers/trailers from and rollback on to not remove them later */ - while (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL || type == HTX_BLK_HDR || type == HTX_BLK_TLR) { + /* Remove partial headers/trailers copied by this call + * from and rollback on to not remove them + * later + */ + while (nb_hdrs && (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL || type == HTX_BLK_HDR || type == HTX_BLK_TLR)) { ret -= meta_sz + htx_get_blksz(dstblk); htx_remove_blk(dst, dstblk); + nb_hdrs--; dstblk = htx_get_tail_blk(dst); blk = htx_get_prev_blk(src, blk); if (!dstblk)