]> git.kaiwu.me - haproxy.git/commit
MINOR: htx: never create, leave nor accept an empty HTX block
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 30 Nov 2026 13:36:36 +0000 (14:36 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 30 Nov 2026 15:03:42 +0000 (16:03 +0100)
commit58ce50527ca672418de17356f7f173d00725d07e
tree4233126089f67a502b3934a10b5127ca12f0a256
parent682ba15b3fecf6567f52fc6028c703fdf59252ac
MINOR: htx: never create, leave nor accept an empty HTX block

An HTX block of any type must never have a size of 0. A zero-sized DATA
block especially has a special meaning on the wire: for a chunked
message, mux-h1 emits a zero-sized chunk, i.e. the last-chunk,
prematurely ending the message for the peer, and any data following in
the HTX message would then be interpreted as a new message (request
smuggling towards a server, response splitting towards a client).

HTX producers are not supposed to leave empty blocks and no way was
found to make a client or server create one, but the HTX API itself
could create or leave them, and the consequence would be dramatic. So
the invariant is now enforced by the HTX API:

  * __htx_add_blk() is the single entry point for block creation, it
    now refuses to create a block of size 0. htx_add_data_atonce() and
    htx_add_last_data() thus also refuse empty data.

  * htx_replace_blk_value() refuses a replacement that would empty the
    block, returning NULL as if there was not enough space. The caller
    must then remove the block itself with htx_remove_blk().

  * htx_change_blk_value_len() and htx_set_blk_value_len() now BUG_ON
    if they would empty a block, except for a header or a trailer whose
    value may legitimately be empty because the name is never empty.

  * htx_cut_data_blk() now BUG_ONs if the cut removes the whole block.

Special blocks (EOH, EOT, NOOP) are created with a size of 1, and no
other block is ever created empty, so no legitimate caller is affected.
The two callers that could produce an empty block were fixed in the two
previous commits.
include/haproxy/htx.h
src/htx.c