]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: cache: Don't cache objects if the size of headers is too big
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 3 Sep 2019 20:22:12 +0000 (22:22 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 4 Sep 2019 08:30:11 +0000 (10:30 +0200)
HTTP responses with headers than impinge upon the reserve must not be
cached. Otherwise, there is no warranty to have enough space to add the header
"Age" when such cached responses are delivered.

This patch must be backported to 2.0 and 1.9. For these versions, the same must
be done for the legacy HTTP mode.

src/cache.c

index 242d7daf0b5a1e43ad89e48c0864e6a3d7e9da2e..24d402abeb219e0f4d40d766904a85e24a7b0e39 100644 (file)
@@ -548,6 +548,7 @@ enum act_return http_action_store_cache(struct act_rule *rule, struct proxy *px,
        unsigned int key = *(unsigned int *)txn->cache_hash;
        struct htx *htx;
        struct http_hdr_ctx ctx;
+       size_t hdrs_len = 0;
        int32_t pos;
 
        /* Don't cache if the response came from a cache */
@@ -618,12 +619,17 @@ enum act_return http_action_store_cache(struct act_rule *rule, struct proxy *px,
                enum htx_blk_type type = htx_get_blk_type(blk);
                uint32_t sz = htx_get_blksz(blk);
 
+               hdrs_len += sizeof(*blk) + sz;
                chunk_memcat(&trash, (char *)&blk->info, sizeof(blk->info));
                chunk_memcat(&trash, htx_get_blk_ptr(htx, blk), sz);
                if (type == HTX_BLK_EOH)
                        break;
        }
 
+       /* Do not cache objects if the headers are too big. */
+       if (hdrs_len > htx->size - global.tune.maxrewrite)
+               goto out;
+
        shctx_lock(shctx);
        first = shctx_row_reserve_hot(shctx, NULL, sizeof(struct cache_entry) + trash.data);
        if (!first) {