BUG/MINOr: hlua: Fix receive from HTTP applet by properly accounting data
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 7 Oct 2025 13:31:27 +0000 (15:31 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 10 Oct 2025 14:43:45 +0000 (16:43 +0200)
A regression was introduced when the commit 5b5ecf848 ("BUG/MINOR: hlua:
Skip headers when a receive is performed on an HTTP applet"). To work
properly, the way consumed data are accounted must be adapted. On the dev
version, the changes were hidden in the HTTP applet refactoring and were not
backported. Because of this issue, it is possible to freeze a lua HTTP
applet.

To fix the issue, the requested length of data to retrieved is only
evaluated when a DATA HTX blocked is processed. Otherwise, the blocked is
just skipped.

The bug was introduced to the 3.2. Thus, there is no upstream commit ID.

This patch should fix issue #3150. It shoukd be backported everywhere the
patch above was backported. So at least as far as 2.8 for now.

(cherry picked from commit 7259dffe8ea5bc820bc7b6d3c2ee0775a09063da)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 59c9496b56059eb5b7144d4d507210a43f326195)
Signed-off-by: Willy Tarreau <w@1wt.eu>

src/hlua.c

index 0b87d9f..a475296 100644 (file)
@@ -5901,20 +5901,17 @@ __LJMP static int hlua_applet_http_recv_yield(lua_State *L, int status, lua_KCon
                uint32_t vlen;
 
                vlen = sz;
-               if (len > 0 && vlen > len)
-                       vlen = len;
-               if (vlen > count) {
-                       if (type != HTX_BLK_DATA)
-                               break;
-                       vlen = count;
-               }
-
                switch (type) {
                        case HTX_BLK_UNUSED:
                                break;
 
                        case HTX_BLK_DATA:
                                v = htx_get_blk_value(htx, blk);
+                               vlen = v.len;
+                               if (len > 0 && vlen > len)
+                                       vlen = len;
+                               if (vlen > count)
+                                       vlen = count;
                                luaL_addlstring(&luactx->b, v.ptr, vlen);
                                if (len > 0)
                                        len -= vlen;