]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: hlua: Detect end of request when reading data for an HTTP applet
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 2 Apr 2021 12:24:56 +0000 (14:24 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 6 Apr 2021 05:31:51 +0000 (07:31 +0200)
When a script retrieves request data from an HTTP applet, line per line or
not, we must be sure to properly detect the end of the request by checking
HTX_FL_EOM flag when everything was consumed. Otherwise, the script may
hang.

It is pretty easy to reproduce the bug by calling applet:receive() without
specifying any length. If the request is not chunked, the function never
returns.

The bug was introduced when the EOM block was removed. Thus, it is specific
to the 2.4. This patch should fix the issue #1207. No backport needed.

src/hlua.c

index a61809e497ad51025ccb43f1f5cad5057bd89a52..45ed28df49f29ca0e0a19ccee1e92dc7fa359d8d 100644 (file)
@@ -4420,6 +4420,12 @@ __LJMP static int hlua_applet_http_getline_yield(lua_State *L, int status, lua_K
                }
        }
 
+       /* The message was fully consumed and no more data are expected
+        * (EOM flag set).
+        */
+       if (htx_is_empty(htx) && (htx->flags & HTX_FL_EOM))
+               stop = 1;
+
        htx_to_buf(htx, &req->buf);
        if (!stop) {
                si_cant_get(si);
@@ -4506,6 +4512,12 @@ __LJMP static int hlua_applet_http_recv_yield(lua_State *L, int status, lua_KCon
                }
        }
 
+       /* The message was fully consumed and no more data are expected
+        * (EOM flag set).
+        */
+       if (htx_is_empty(htx) && (htx->flags & HTX_FL_EOM))
+               len = 0;
+
        htx_to_buf(htx, &req->buf);
 
        /* If we are no other data available, yield waiting for new data. */