]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: mux-h1: Properly ignore trailers when a content-length is announced
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 27 Nov 2023 07:23:45 +0000 (08:23 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 27 Nov 2023 07:37:48 +0000 (08:37 +0100)
It is not possible in H1, but in H2 (and probably H3) it is possible to have
trailers at the end of a message while a Content-Length was announced.

However, depending if the trailers are received with the last HTX DATA block
or the zero-copy forwarding is used or not, an processing error may be
triggered, leading to a 500-internal-error.

To fix the issue, when a content-length is announced and all the payload was
processed, we switch the message to H1_MSG_DONE state only if the
end-of-message was also reported (HTX_FL_EOM flag set). Otherwise, it is
switched to H1_MSG_TRAILERS state to be able to properly ignored the
trailers, if so.

The patch must be backported as far as 2.4. Be careful, this part was highly
refactored. The patch will have to be adapted to be backported.

src/mux_h1.c

index 63eb78e1c3bd6212d5166ddb4d48b0e512a5e93f..73338774cb2d2addb1fe94bb8a3fa35d7207d7da 100644 (file)
@@ -2485,7 +2485,7 @@ static size_t h1_make_eoh(struct h1s *h1s, struct h1m *h1m, struct htx *htx, siz
                }
                else if (!chunk_memcat(&outbuf, "\r\n", 2))
                        goto full;
-               h1m->state = H1_MSG_DONE;
+               h1m->state = ((htx->flags & HTX_FL_EOM) ? H1_MSG_DONE : H1_MSG_TRAILERS);
        }
        else {
                if (!chunk_memcat(&outbuf, "\r\n", 2))
@@ -2577,7 +2577,7 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf,
                        }
                        h1m->curr_len -= count;
                        if (!h1m->curr_len)
-                               h1m->state = H1_MSG_DONE;
+                               h1m->state = (eom ? H1_MSG_DONE : H1_MSG_TRAILERS);
                }
                else if (h1m->flags & H1_MF_CHNK) {
                        /* The message is chunked. We need to check if we must
@@ -4530,7 +4530,7 @@ static size_t h1_done_ff(struct stconn *sc)
                h1m->curr_len -= total;
 
        if (!h1m->curr_len && (h1m->flags & H1_MF_CLEN))
-               h1m->state = H1_MSG_DONE;
+               h1m->state = ((sd->iobuf.flags & IOBUF_FL_EOI) ? H1_MSG_DONE : H1_MSG_TRAILERS);
        else if (!h1m->curr_len && (h1m->flags & H1_MF_CHNK)) {
                if (h1m->state == H1_MSG_DATA)
                        h1m->state = H1_MSG_CHUNK_CRLF;