From: Christopher Faulet Date: Thu, 3 Dec 2026 09:27:50 +0000 (+0100) Subject: BUG/MINOR: hlua: do nothing in set_eom() if the message is already ended X-Git-Url: https://git.kaiwu.me/web/http/static/%7B@url%7D?a=commitdiff_plain;h=f57fb8162d23f7c9126a41b8b476f476adfd5fe7;p=haproxy.git BUG/MINOR: hlua: do nothing in set_eom() if the message is already ended HTTPMessage:set_eom() called htx_set_eom() without checking the state of the message. If the end of the message was already reached, the EOM flag could be reported twice: when the block carrying it was already forwarded, the message could be empty and a NOOP block carrying the EOM flag was then added. And, in a tunnel, the BUG_ON() in htx_set_eom() could be triggered, the tail block being a RAW_DATA block. It could also be triggered if the tail block was not a block that can carry the EOM flag. Now, nothing is done if the message is already ended, the message state being also checked. And an error is raised if the EOM flag cannot be set on the tail block. The documentation was updated accordingly. This patch must be backported to 3.5. --- diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst index bd8f581bb..b641aa27d 100644 --- a/doc/lua-api/index.rst +++ b/doc/lua-api/index.rst @@ -4750,7 +4750,9 @@ HTTPMessage class can only be called when all data of the message are visible by the current filter. Otherwise, an error is raised, because an earlier filter holding data back may already have reached the end of the message, or may expose - data after it. + data after it. Nothing is done if the end of the message was already + reached. An error is also raised if the message is incomplete, for instance + if its headers or its trailers were not fully received. :param class_httpmessage http_msg: The manipulated HTTP message. diff --git a/src/hlua.c b/src/hlua.c index 61545601e..6865aee45 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -7981,7 +7981,26 @@ __LJMP static int hlua_http_msg_set_eom(lua_State *L) if (!hlua_http_msg_fully_visible(L, msg, htx)) WILL_LJMP(luaL_error(L, "The 'set_eom' function cannot be called when not all data are visible.")); - htx_set_eom(htx); + /* Nothing to do if the end of the message was already reached. The + * block carrying the EOM flag may have already been forwarded, so the + * message state must be checked too. Note it also covers tunnels. + */ + if (htx_msg_ended(htx) || msg->msg_state >= HTTP_MSG_ENDING) + return 0; + + /* The EOM flag can only be carried by an EOH, a DATA, an EOT or a + * NOOP block. A NOOP block is added if the message is empty. + */ + if (!htx_is_empty(htx)) { + enum htx_blk_type type = htx_get_tail_type(htx); + + if (type != HTX_BLK_EOH && type != HTX_BLK_DATA && + type != HTX_BLK_EOT && type != HTX_BLK_NOOP) + WILL_LJMP(luaL_error(L, "The 'set_eom' function cannot be called on an incomplete message.")); + } + + if (!htx_set_eom(htx)) + WILL_LJMP(luaL_error(L, "Unable to set the end of message.")); return 0; }