]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: http_client: Don't add input data on an empty request buffer
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 7 Apr 2022 08:47:07 +0000 (10:47 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 7 Apr 2022 09:04:39 +0000 (11:04 +0200)
When compiled in debug mode, a BUG_ON triggers an error when the payload is
fully transfered from the http-client buffer to the request channel
buffer. In fact, when channel_add_input() is called, the request buffer is
empty. So an error is reported when those data are directly forwarded,
because we try to add some output data on a buffer with no data.

To fix the bug, we must be sure to call channel_add_input() after the data
transfer.

The bug was introduced by the commit ccc7ee45f ("MINOR: httpclient: enable
request buffering"). So, this patch must be backported if the above commit
is backported.

src/http_client.c

index e8d7b05c5419c47b0c5d48302b21b1f50f786910..33213a88f5b8745c399c7bde4ee4b7b009fb3e1e 100644 (file)
@@ -702,13 +702,15 @@ static void httpclient_applet_io_handler(struct appctx *appctx)
                                                        goto more;
 
                                                if (htx_is_empty(htx)) {
+                                                       size_t data = hc_htx->data;
+
                                                        /* Here htx_to_buf() will set buffer data to 0 because
                                                         * the HTX is empty, and allow us to do an xfer.
                                                         */
                                                        htx_to_buf(hc_htx, &hc->req.buf);
                                                        htx_to_buf(htx, &req->buf);
-                                                       channel_add_input(req, hc_htx->data);
                                                        b_xfer(&req->buf, &hc->req.buf, b_data(&hc->req.buf));
+                                                       channel_add_input(req, data);
                                                } else {
                                                        struct htx_ret ret;