BUG/MINOR: h3: fix TRAILERS encoding

HTTP/3 trailers encoding was never working as intended. It's because
h3_trailers_to_htx() manipulate a newly allocated buffer instead of the
already existing channel one. Thus, HTX message handled by the stream
was incomplete as it lacked trailers and EOM.

Fix this by reusing the already allocated channel buffer in
h3_trailers_to_htx().

This bug was detected by simulating TRAILERS emission which generate
CL--- state due to missing request side termination signal. Its impact
is deemed as minimal as trailers are pretty infrequent for now in
HTTP/3.

This must be backported up to 2.7.
This commit is contained in:
Amaury Denoyelle 2023-11-28 15:59:38 +01:00
parent 07691a2e7c
commit 81a4cc666d

View File

@ -846,8 +846,8 @@ static ssize_t h3_trailers_to_htx(struct qcs *qcs, const struct buffer *buf,
{ {
struct h3s *h3s = qcs->ctx; struct h3s *h3s = qcs->ctx;
struct h3c *h3c = h3s->h3c; struct h3c *h3c = h3s->h3c;
struct buffer htx_buf = BUF_NULL;
struct buffer *tmp = get_trash_chunk(); struct buffer *tmp = get_trash_chunk();
struct buffer *appbuf = NULL;
struct htx *htx = NULL; struct htx *htx = NULL;
struct htx_sl *sl; struct htx_sl *sl;
struct http_hdr list[global.tune.max_http_hdr]; struct http_hdr list[global.tune.max_http_hdr];
@ -868,14 +868,14 @@ static ssize_t h3_trailers_to_htx(struct qcs *qcs, const struct buffer *buf,
goto out; goto out;
} }
if (!qcs_get_buf(qcs, &htx_buf)) { if (!(appbuf = qcs_get_buf(qcs, &qcs->rx.app_buf))) {
TRACE_ERROR("HTX buffer alloc failure", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs); TRACE_ERROR("HTX buffer alloc failure", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
h3c->err = H3_INTERNAL_ERROR; h3c->err = H3_INTERNAL_ERROR;
len = -1; len = -1;
goto out; goto out;
} }
BUG_ON(!b_size(&htx_buf)); /* TODO */ BUG_ON(!b_size(appbuf)); /* TODO */
htx = htx_from_buf(&htx_buf); htx = htx_from_buf(appbuf);
if (!h3s->data_len) { if (!h3s->data_len) {
/* Notify that no body is present. This can only happens if /* Notify that no body is present. This can only happens if
@ -972,13 +972,10 @@ static ssize_t h3_trailers_to_htx(struct qcs *qcs, const struct buffer *buf,
if (fin) if (fin)
htx->flags |= HTX_FL_EOM; htx->flags |= HTX_FL_EOM;
htx_to_buf(htx, &htx_buf);
htx = NULL;
out: out:
/* HTX may be non NULL if error before previous htx_to_buf(). */ /* HTX may be non NULL if error before previous htx_to_buf(). */
if (htx) if (appbuf)
htx_to_buf(htx, &htx_buf); htx_to_buf(htx, appbuf);
TRACE_LEAVE(H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs); TRACE_LEAVE(H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
return len; return len;