BUG/MINOR: http_client: Don't add input data on an empty request buffer

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.
This commit is contained in:
Christopher Faulet 2022-04-07 10:47:07 +02:00
parent 2eb5243e7f
commit dca3b5b2c6

View 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;