]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: httpclient: remove the UNUSED block when parsing headers
authorWilliam Lallemand <wlallemand@haproxy.org>
Wed, 9 Mar 2022 17:56:02 +0000 (18:56 +0100)
committerWilliam Lallemand <wlallemand@haproxy.org>
Mon, 14 Mar 2022 14:10:12 +0000 (15:10 +0100)
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

index f17e805e6d9c1f05b24d8d7c91cfd0731981323d..94b192a6c7bbe5aa91a523c097321dd90de61b2c 100644 (file)
@@ -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) {