From 621a0b5a398b9de1633381c69ca7657d30dcd72f Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Mon, 8 Feb 2021 17:18:01 +0100 Subject: [PATCH] BUG/MEDIUM: mux-h1: Always set CS_FL_EOI for response in MSG_DONE state During the message parsing, if in MSG_DONE state, the CS_FL_EOI flag must always be set on the conn-stream if following conditions are met : * It is a response or * It is a request but not a protocol upgrade nor a CONNECT. For now, there is no test on the message type (request or response). Thus the CS_FL_EOI flag is not set for a response with a "Connection: upgrade" header but not a 101 response. This bug was introduced by the commit 3e1748bbf ("BUG/MINOR: mux-h1: Don't set CS_FL_EOI too early for protocol upgrade requests"). It was backported as far as 2.0. Thus, this patch must also be backported as far as 2.0. (cherry picked from commit a22782b597ee9a3bfecb18a66e29633c8e814216) [cf: context adjustments] Signed-off-by: Christopher Faulet (cherry picked from commit d50c18f9c78d0ba0ff357c9a8b51941a8cda3441) Signed-off-by: Christopher Faulet (cherry picked from commit 9da31b5bfc5716f123567293fd579e54aff540e1) Signed-off-by: Christopher Faulet --- src/mux_h1.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/mux_h1.c b/src/mux_h1.c index 802d150..31f0f17 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -1389,12 +1389,17 @@ static size_t h1_process_eom(struct h1s *h1s, struct h1m *h1m, struct htx *htx, return 0; } + h1s->flags &= ~H1S_F_APPEND_EOM; h1m->state = H1_MSG_DONE; - /* Don't set EOI on the conn-stream for protocol upgrade requests, wait - * the response to do so or not depending on the status code. - */ - if (!(h1m->flags & H1_MF_CONN_UPG)) + /* Set EOI on conn-stream in DONE state iff: + * - it is a response + * - it is a request but no a protocol upgrade nor a CONNECT + * + * If not set, Wait the response to do so or not depending on the status + * code. + */ + if ((h1m->flags & H1_MF_RESP) || ((h1s->meth != HTTP_METH_CONNECT) && !(h1m->flags & H1_MF_CONN_UPG))) h1s->cs->flags |= CS_FL_EOI; TRACE_STATE("end of message", H1_EV_RX_DATA|H1_EV_RX_EOI, h1s->h1c->conn, h1s); TRACE_LEAVE(H1_EV_RX_DATA, h1s->h1c->conn, h1s); -- 1.7.10.4