BUG/MEDIUM: cache/filters: Fix loop on HTX blocks caching the response payload
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 2 Mar 2020 15:19:50 +0000 (16:19 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Mar 2020 14:52:57 +0000 (16:52 +0200)
During the payload filtering, the offset is relative to the head of the HTX
message and not its first index. This index is the position of the first block
to (re)start the HTTP analysis. It must be used during HTTP analysis but not
during the payload forwarding.

So, from the cache point of view, when we loop on the HTX blocks to cache the
response payload, we must start from the head of the HTX message. To ease the
loop, we use the function htx_find_offset().

This patch must be backported as far as 2.0. It depends on the commit "MINOR:
htx: Add a function to return a block at a specific an offset". So this one must
be backported first.

(cherry picked from commit 497c7595588371e8ac85c322825455d7c7d4e407)
Signed-off-by: Willy Tarreau <w@1wt.eu>

src/cache.c

index dc11cf5..b70f2a9 100644 (file)
@@ -313,6 +313,7 @@ cache_store_http_payload(struct stream *s, struct filter *filter, struct http_ms
        struct htx *htx = htxbuf(&msg->chn->buf);
        struct htx_blk *blk;
        struct shared_block *fb;
+       struct htx_ret htxret;
        unsigned int orig_len, to_forward;
        int ret;
 
@@ -327,16 +328,15 @@ cache_store_http_payload(struct stream *s, struct filter *filter, struct http_ms
        chunk_reset(&trash);
        orig_len = len;
        to_forward = 0;
-       for (blk = htx_get_first_blk(htx); blk && len; blk = htx_get_next_blk(htx, blk)) {
+
+       htxret = htx_find_offset(htx, offset);
+       blk = htxret.blk;
+       offset = htxret.ret;
+       for (; blk && len; blk = htx_get_next_blk(htx, blk)) {
                enum htx_blk_type type = htx_get_blk_type(blk);
                uint32_t info, sz = htx_get_blksz(blk);
                struct ist v;
 
-               if (offset >= sz) {
-                       offset -= sz;
-                       continue;
-               }
-
                switch (type) {
                        case HTX_BLK_UNUSED:
                                break;