From: Christopher Faulet Date: Tue, 24 Nov 2026 21:22:47 +0000 (+0100) Subject: BUG/MINOR: mux-h1: properly handle NOOP blocks and track EOM emission X-Git-Tag: v3.5-dev14~30 X-Git-Url: https://git.kaiwu.me/http/ngx_http_ssi_module.html?a=commitdiff_plain;h=e99253b70269ef455eaa8576acd839012a7bd312;p=haproxy.git BUG/MINOR: mux-h1: properly handle NOOP blocks and track EOM emission An HTX NOOP block may carry the EOM flag, notably when the end of the message is reported on an empty HTX message. This is what happens when an H3 request is received with trailers that do not end the stream: h3_trailers_to_htx() emits an EOT block without the EOM flag when the FIN was not received with the trailers, and when the FIN later arrives in a separate empty STREAM frame, which is valid per RFC 9114, qcs_http_handle_standalone_fin() calls htx_set_eom() which adds a NOOP block carrying the EOM flag. On an H1 server, this block arrives after the H1 mux reached the DONE state, which was a processing error: the request failed with a 500 and "IH--" (or "ID--") termination flags. The H1 mux now tracks the EOM emission with a new H1S_F_EOM_SENT flag, set when the last chunk is emitted (h1_make_eoh, h1_make_data) or when the EOT block carrying EOM is processed in h1_make_trailers. The new h1_make_done() function handles the DONE state: it consumes NOOP blocks, reporting the EOM on the first one carrying the flag, and skips RAW_DATA blocks after a tunnel rejection on the backend side, replacing the now removed h1_skip_tunnel() function. This way, a late EOM block received in DONE state properly terminates the message instead of raising a processing error. This also fixes the EOM reporting on an empty HTX message by applets and HTTP analyzers, which produced a NOOP block rejected by the DONE-state processing. This fix must not be backported because it relies on HTX changes performed in 3.5. --- diff --git a/include/haproxy/mux_h1-t.h b/include/haproxy/mux_h1-t.h index a886d364c..03e858bd8 100644 --- a/include/haproxy/mux_h1-t.h +++ b/include/haproxy/mux_h1-t.h @@ -93,7 +93,7 @@ static forceinline char *h1c_show_flags(char *buf, size_t len, const char *delim #define H1S_F_WANT_CLO 0x00000040 #define H1S_F_WANT_MSK 0x00000070 #define H1S_F_NOT_FIRST 0x00000080 /* The H1 stream is not the first one */ -/* 0x00000100 unused */ +#define H1S_F_EOM_SENT 0x00000100 /* The end of message was sent */ #define H1S_F_INTERNAL_ERROR 0x00000200 /* Set when an internal error occurred during the message parsing */ #define H1S_F_NOT_IMPL_ERROR 0x00000400 /* Set when a feature is not implemented during the message parsing */ @@ -124,10 +124,10 @@ static forceinline char *h1s_show_flags(char *buf, size_t len, const char *delim /* flags */ _(H1S_F_RX_BLK, _(H1S_F_TX_BLK, _(H1S_F_RX_CONGESTED, _(H1S_F_WANT_KAL, _(H1S_F_WANT_TUN, _(H1S_F_WANT_CLO, - _(H1S_F_NOT_FIRST, + _(H1S_F_NOT_FIRST, _(H1S_F_EOM_SENT, _(H1S_F_INTERNAL_ERROR, _(H1S_F_NOT_IMPL_ERROR, _(H1S_F_PARSING_ERROR, _(H1S_F_PROCESSING_ERROR, _(H1S_F_HAVE_SRV_NAME, _(H1S_F_HAVE_O_CONN, _(H1S_F_HAVE_WS_KEY, - _(H1S_F_HAVE_CLEN, _(H1S_F_HAVE_CHNK, _(H1S_F_BODYLESS_REQ, _(H1S_F_BODYLESS_RESP)))))))))))))))))); + _(H1S_F_HAVE_CLEN, _(H1S_F_HAVE_CHNK, _(H1S_F_BODYLESS_REQ, _(H1S_F_BODYLESS_RESP))))))))))))))))))); /* epilogue */ _(~0U); return buf; diff --git a/src/mux_h1.c b/src/mux_h1.c index b1eb0bf23..136b850a0 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -3073,6 +3073,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; + h1s->flags |= H1S_F_EOM_SENT; h1m->state = H1_MSG_DONE; } else { @@ -3407,14 +3408,21 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf, goto full; } - if (last_data) + if (last_data) { h1m->state = H1_MSG_DONE; + break; + } } copy: TRACE_PROTO("H1 message payload data xferred", H1_EV_TX_DATA|H1_EV_TX_BODY, h1c->conn, h1s, 0, (size_t[]){ret}); b_add(&h1c->obuf, outbuf.data); end: + if (h1m->state == H1_MSG_DONE) { + /* MSG_DONE here means EOM was seen */ + h1s->flags |= H1S_F_EOM_SENT; + } + TRACE_LEAVE(H1_EV_TX_DATA|H1_EV_TX_BODY, h1c->conn, h1s, htx, (size_t[]){ret}); return ret; full: @@ -3511,7 +3519,9 @@ static size_t h1_make_tunnel(struct h1s *h1s, struct h1m *h1m, struct buffer *bu goto full; } else if (type == HTX_BLK_NOOP) { - /* Consume the NOOP block, nothing is emitted */ + /* Consume the NOOP block, nothing is emitted. But EOM flag is unexpected */ + if (blk->flags & HTX_BLK_FL_EOM) + goto error; } else goto error; @@ -3550,59 +3560,6 @@ static size_t h1_make_tunnel(struct h1s *h1s, struct h1m *h1m, struct buffer *bu goto end; } -/* Skip tunneled data from the HTX message for the stream . Both - * the request and the response are in DONE state on the server side and no - * tunnel was established. Some raw data may still be in flight and must be - * discarded instead of reporting a processing error. Return the number of - * bytes consumed, at most , or zero if nothing was done or on error. - */ -static size_t h1_skip_tunnel(struct h1s *h1s, struct htx *htx, size_t count) -{ - struct h1c *h1c = h1s->h1c; - struct htx_blk *blk; - enum htx_blk_type type; - uint32_t sz; - size_t ret = 0; - - TRACE_ENTER(H1_EV_TX_DATA|H1_EV_TX_BODY, h1c->conn, h1s, htx, (size_t[]){count}); - - blk = htx_get_head_blk(htx); - - while (blk && count) { - uint32_t vlen; - - type = htx_get_blk_type(blk); - if (type != HTX_BLK_RAW_DATA) - goto error; - - sz = htx_get_blksz(blk); - vlen = MIN(sz, count); - ret += vlen; - count -= vlen; - if (sz == vlen) - blk = htx_remove_blk(htx, blk); - else { - htx_cut_data_blk(htx, blk, vlen); - break; - } - } - - TRACE_PROTO("H1 tunneled data skipped", H1_EV_TX_DATA|H1_EV_TX_BODY, h1c->conn, h1s, htx, (size_t[]){ret}); - - end: - TRACE_LEAVE(H1_EV_TX_DATA|H1_EV_TX_BODY, h1c->conn, h1s, htx, (size_t[]){ret}); - return ret; - - error: - ret = 0; - htx->flags |= HTX_FL_PROCESSING_ERROR; - h1s->flags |= H1S_F_PROCESSING_ERROR; - se_fl_set(h1s->sd, SE_FL_ERROR); - TRACE_ERROR("processing error on tunneled", - H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s); - goto end; -} - /* Try to send the trailers from the HTX message for the stream . It * returns the number of bytes consumed or zero if nothing was done or if an * error occurred. No more than bytes can be sent. @@ -3671,15 +3628,22 @@ static size_t h1_make_trailers(struct h1s *h1s, struct h1m *h1m, struct htx *htx H1_EV_TX_DATA|H1_EV_TX_TLRS, h1c->conn, h1s); } h1m->state = H1_MSG_DONE; + if (blk->flags & HTX_BLK_FL_EOM) + h1s->flags |= H1S_F_EOM_SENT; } else if (type == HTX_BLK_NOOP) { - /* Consume the NOOP block, nothing is emitted */ + /* Consume the NOOP block, nothing is emitted. But EOM is unexpected before EOT */ + if (blk->flags & HTX_BLK_FL_EOM) + goto error; } nextblk: ret += sz; count -= sz; blk = htx_remove_blk(htx, blk); + + if (h1m->state == H1_MSG_DONE) + break; } copy: @@ -3747,6 +3711,77 @@ full: goto end; } +/* Process HTX blocks in DONE state. There is noting more to send here but some + * blocks may still be there: NOOP blocks, but only one can carry the EOM flag, + * or RAW_DATA blocks after a tunnel rejection (on backend side, EOM seen and + * response in done state). All other blocks are rejected with an error. + * Return the number of bytes consumed, at most , or zero if nothing was + * done or on error. + */ +static size_t h1_make_done(struct h1s *h1s, struct htx *htx, size_t count) +{ + struct h1c *h1c = h1s->h1c; + struct htx_blk *blk; + enum htx_blk_type type; + uint32_t sz; + size_t ret = 0; + + TRACE_ENTER(H1_EV_TX_DATA|H1_EV_TX_BODY, h1c->conn, h1s, htx, (size_t[]){count}); + + blk = htx_get_head_blk(htx); + + while (blk && count) { + uint32_t vlen; + + type = htx_get_blk_type(blk); + sz = htx_get_blksz(blk); + vlen = sz; + + if (type == HTX_BLK_NOOP) { + if (blk->flags & HTX_BLK_FL_EOM) { + if (h1s->flags & H1S_F_EOM_SENT) + goto error; + h1s->flags |= H1S_F_EOM_SENT; + } + } + else if (type == HTX_BLK_RAW_DATA) { + if (!(h1c->flags & H1C_F_IS_BACK) || + !(h1s->flags & H1S_F_EOM_SENT) || + h1s->res.state != H1_MSG_DONE) + goto error; + + if (vlen > count) + vlen = count; + TRACE_PROTO("H1 tunneled data skipped", H1_EV_TX_DATA|H1_EV_TX_BODY, h1c->conn, h1s, htx, (size_t[]){ret}); + } + else + goto error; + + ret += vlen; + count -= vlen; + if (sz == vlen) + blk = htx_remove_blk(htx, blk); + else { + htx_cut_data_blk(htx, blk, vlen); + break; + } + } + + + end: + TRACE_LEAVE(H1_EV_TX_DATA|H1_EV_TX_BODY, h1c->conn, h1s, htx, (size_t[]){ret}); + return ret; + + error: + ret = 0; + htx->flags |= HTX_FL_PROCESSING_ERROR; + h1s->flags |= H1S_F_PROCESSING_ERROR; + se_fl_set(h1s->sd, SE_FL_ERROR); + TRACE_ERROR("processing error in done state", + H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s); + goto end; +} + /* * Process outgoing data. It parses data and transfer them from the channel buffer into * h1c->obuf. It returns the number of bytes parsed and transferred if > 0, or @@ -3817,12 +3852,8 @@ static size_t h1_process_mux(struct h1c *h1c, struct buffer *buf, size_t count) break; case H1_MSG_DONE: - if ((h1c->flags & H1C_F_IS_BACK) && h1s->res.state == H1_MSG_DONE) { - ret = h1_skip_tunnel(h1s, htx, count); - break; - } - TRACE_STATE("unexpected data xferred in done state", H1_EV_TX_DATA|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s); - __fallthrough; + ret = h1_make_done(h1s, htx, count); + break; default: ret = 0;