From: Christopher Faulet Date: Wed, 25 Nov 2020 07:08:08 +0000 (+0100) Subject: BUG/MINOR: http-fetch: Fix smp_fetch_body() when called from a health-check X-Git-Tag: v2.4-dev2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a9ffc416377e0df9859526dc3c1d769c6a68636f;p=thirdparty%2Fhaproxy.git BUG/MINOR: http-fetch: Fix smp_fetch_body() when called from a health-check res.body may be called from a health-check. It is probably never used. But it is possibe. In such case, there is no channel. Thus we must not use it unconditionally to set the flag SMP_F_MAY_CHANGE on the smp. Now the condition test the channel first. In addtion, the flag is not set if the payload is fully received. This patch must be backported as far as 2.2. --- diff --git a/src/http_fetch.c b/src/http_fetch.c index 595e0e3189..a0b9cf57ff 100644 --- a/src/http_fetch.c +++ b/src/http_fetch.c @@ -587,6 +587,7 @@ static int smp_fetch_body(const struct arg *args, struct sample *smp, const char struct htx *htx = smp_prefetch_htx(smp, chn, check, 1); struct buffer *temp; int32_t pos; + int finished = 0; if (!htx) return 0; @@ -596,8 +597,10 @@ static int smp_fetch_body(const struct arg *args, struct sample *smp, const char struct htx_blk *blk = htx_get_blk(htx, pos); enum htx_blk_type type = htx_get_blk_type(blk); - if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT) + if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT) { + finished = 1; break; + } if (type == HTX_BLK_DATA) { if (!h1_format_htx_data(htx_get_blk_value(htx, blk), temp, 0)) return 0; @@ -608,7 +611,8 @@ static int smp_fetch_body(const struct arg *args, struct sample *smp, const char smp->data.u.str = *temp; smp->flags = SMP_F_VOL_TEST; - if (!channel_full(chn, global.tune.maxrewrite) && !(chn->flags & (CF_EOI|CF_SHUTR|CF_READ_ERROR))) + if (!finished && (check || (chn && !channel_full(chn, global.tune.maxrewrite) && + !(chn->flags & (CF_EOI|CF_SHUTR|CF_READ_ERROR))))) smp->flags |= SMP_F_MAY_CHANGE; return 1;