From: Christopher Faulet Date: Fri, 23 Oct 2026 07:23:28 +0000 (+0200) Subject: BUG/MINOR: hlua/filters: Restrict HTTPMessage.set_eom/unset_eom to visible data X-Git-Tag: v3.5-dev10~60 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=4c29e446044f4f0c85bba80158b370eae228ac6e;p=haproxy.git BUG/MINOR: hlua/filters: Restrict HTTPMessage.set_eom/unset_eom to visible data HTTPMessage.set_eom() and HTTPMessage.unset_eom() manipulate the EOM flag of the whole HTX message, without checking the data visible by the calling filter. But when several Lua filters are chained on a channel and an earlier one holds back some data (for instance to rewrite the body), the end of the message may be reached by this filter while the current one still waits for data held upstream. In that case, setting the EOM would duplicate it, and unsetting it could not remove the flag from the data held by the earlier filter. Now both functions can only be called when all data of the message are visible by the current filter, like HTTPMessage.eom(), HTTPMessage.may_recv() and HTTPMessage.closed(). Otherwise an error is raised. The error message of HTTPMessage.unset_eom() was also fixed: it referred to the 'set_eom' function. This patch should be backported to all supported versions. --- diff --git a/src/hlua.c b/src/hlua.c index f3ad67453..9a51f1b27 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -7949,6 +7949,15 @@ __LJMP static int hlua_http_msg_set_eom(lua_State *L) MAY_LJMP(check_args(L, 1, "set_eom")); msg = MAY_LJMP(hlua_checkhttpmsg(L, 1)); htx = htxbuf(&msg->chn->buf); + + /* Setting the EOM is only meaningful on data visible by the current + * filter. Otherwise, the end of the message may already be reached, + * an earlier filter holding data back, and setting it again would + * duplicate it. + */ + 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); return 0; } @@ -7964,9 +7973,18 @@ __LJMP static int hlua_http_msg_unset_eom(lua_State *L) struct htx *htx; struct htx_blk *blk; - MAY_LJMP(check_args(L, 1, "set_eom")); + MAY_LJMP(check_args(L, 1, "unset_eom")); msg = MAY_LJMP(hlua_checkhttpmsg(L, 1)); htx = htxbuf(&msg->chn->buf); + + /* Unsetting the EOM is only meaningful on data visible by the current + * filter. Otherwise, the end of the message may not be reached yet, an + * earlier filter holding data back, and the flag could not be removed + * from it. + */ + if (!hlua_http_msg_fully_visible(L, msg, htx)) + WILL_LJMP(luaL_error(L, "The 'unset_eom' function cannot be called when not all data are visible.")); + if (!htx_msg_ended(htx)) return 0;