From c020b2505d4d5a94d1b465a4e6e73c1f5ef86170 Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Wed, 9 Mar 2022 18:56:02 +0100 Subject: [PATCH] BUG/MINOR: httpclient: remove the UNUSED block when parsing headers Remove the UNUSED blocks when iterating on headers, we should not stop when encountering one. We should only stop iterating once we found the EOH block. It doesn't provoke a problem, since we don't manipulates the headers before treating them, but it could evolve in the future. Must be backported to 2.5. --- src/http_client.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/http_client.c b/src/http_client.c index f17e805e6..94b192a6c 100644 --- a/src/http_client.c +++ b/src/http_client.c @@ -787,24 +787,29 @@ static void httpclient_applet_io_handler(struct appctx *appctx) enum htx_blk_type type = htx_get_blk_type(blk); uint32_t sz = htx_get_blksz(blk); + if (type == HTX_BLK_UNUSED) { + c_rew(res, sz); + htx_remove_blk(htx, blk); + } + + if (type == HTX_BLK_HDR) { + hdrs[hdr_num].n = istdup(htx_get_blk_name(htx, blk)); + hdrs[hdr_num].v = istdup(htx_get_blk_value(htx, blk)); + if (!isttest(hdrs[hdr_num].v) || !isttest(hdrs[hdr_num].n)) + goto end; + c_rew(res, sz); + htx_remove_blk(htx, blk); + hdr_num++; + } + + /* create a NULL end of array and leave the loop */ if (type == HTX_BLK_EOH) { hdrs[hdr_num].n = IST_NULL; hdrs[hdr_num].v = IST_NULL; - co_set_data(res, co_data(res) - sz); + c_rew(res, sz); htx_remove_blk(htx, blk); break; } - - if (type != HTX_BLK_HDR) - break; - - hdrs[hdr_num].n = istdup(htx_get_blk_name(htx, blk)); - hdrs[hdr_num].v = istdup(htx_get_blk_value(htx, blk)); - if (!isttest(hdrs[hdr_num].v) || !isttest(hdrs[hdr_num].n)) - goto end; - co_set_data(res, co_data(res) - sz); - htx_remove_blk(htx, blk); - hdr_num++; } if (hdr_num) {