]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: hlua/filters: Restrict HTTPMessage.set_eom/unset_eom to visible data
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 23 Oct 2026 07:23:28 +0000 (09:23 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 23 Oct 2026 17:43:33 +0000 (19:43 +0200)
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.

src/hlua.c

index f3ad674532a52ed280ecc3377500d2381103c118..9a51f1b27c4581055d3e343b7d2213adb7043754 100644 (file)
@@ -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;