]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: hlua: do nothing in set_eom() if the message is already ended
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 3 Dec 2026 09:27:50 +0000 (10:27 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 3 Dec 2026 12:41:06 +0000 (13:41 +0100)
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.

doc/lua-api/index.rst
src/hlua.c

index bd8f581bb8fdb7217d3e62689669e90d46ea1fd1..b641aa27d2b9affa2f7873735d65594c2858437c 100644 (file)
@@ -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.
 
index 61545601e386dac8a724a6bee661f9149c105182..6865aee457565b4a30fc7c697b58929942bea34d 100644 (file)
@@ -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;
 }