]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: mux-h1: never negotiate a zero-sized chunk in h1_nego_ff()
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 1 Dec 2026 11:07:51 +0000 (12:07 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 3 Dec 2026 12:41:06 +0000 (13:41 +0100)
In h1_nego_ff(), with NEGO_FF_FL_EXACT_SIZE and a chunked message in
CHUNK_CRLF/CHUNK_SIZE state, a producer calling with <count> == 0 makes
h1_make_chunk() emit "0\r\n", i.e. the last-chunk, prematurely ending the
message for the peer.

No case was found where it happens. The stream connectors (sc_conn_recv()
and sc_applet_recv()) only call the producers to fast-forward data when
there is something to forward. But it is not true for all producers. For
instance, haterm may negotiate with <count> == 0 when its splicing pipe
still contains data while everything was already produced. In that case,
the message is already finished, and the fast-forwarding is disabled
because of the message state. But nothing in h1_nego_ff() prevents it for
a chunked message.

So let's harden it: when <count> is 0, no chunk is started. The iobuf is
still set up as usual, so the producer can safely use it, and nothing is
forwarded. The IOBUF_FL_NO_FF flag is not set because <count> == 0 is a
transient condition, and this flag would permanently disable the
fast-forwarding for the stream.

src/mux_h1.c

index c8ee5b011228d28766d343128aba4e06c8f6663d..b77f70080e9f0001b2226b955050ea1fcfe2e477 100644 (file)
@@ -5230,7 +5230,6 @@ static size_t h1_nego_ff(struct stconn *sc, struct buffer *input, size_t count,
 
        TRACE_ENTER(H1_EV_STRM_SEND, h1c->conn, h1s, 0, (size_t[]){count});
 
-
        if (global.tune.no_zero_copy_fwd & NO_ZERO_COPY_FWD_H1_SND) {
                h1s->sd->iobuf.flags |= IOBUF_FL_NO_FF;
                goto out;
@@ -5271,12 +5270,19 @@ static size_t h1_nego_ff(struct stconn *sc, struct buffer *input, size_t count,
                else {
                        BUG_ON(h1m->state != H1_MSG_CHUNK_CRLF && h1m->state != H1_MSG_CHUNK_SIZE);
                        if (flags & NEGO_FF_FL_EXACT_SIZE) {
-                               if (!h1_make_chunk(h1s, h1m, count)) {
-                                       h1s->sd->iobuf.flags |= IOBUF_FL_FF_BLOCKED;
-                                       goto out;
+                               /* Never emit a zero-sized chunk. It is the
+                                * last-chunk, it would prematurely end the
+                                * message. With <count> == 0, nothing will be
+                                * forwarded, so no chunk is started.
+                                */
+                               if (count) {
+                                       if (!h1_make_chunk(h1s, h1m, count)) {
+                                               h1s->sd->iobuf.flags |= IOBUF_FL_FF_BLOCKED;
+                                               goto out;
+                                       }
+                                       h1m->curr_len = count;
+                                       h1s_consume_kop(h1s, h1m->curr_len);
                                }
-                               h1m->curr_len = count;
-                               h1s_consume_kop(h1s, h1m->curr_len);
                        }
                        else {
                                /* The producer does not know the chunk size, thus this will be emitted at the