From dca3b5b2c6618860b305b48b5c55abe2877be832 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 7 Apr 2022 10:47:07 +0200 Subject: [PATCH] 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. --- src/http_client.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/http_client.c b/src/http_client.c index e8d7b05c5..33213a88f 100644 --- a/src/http_client.c +++ b/src/http_client.c @@ -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;