]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: lua/socket: Length required read doesn't work
authorThierry FOURNIER <thierry.fournier@ozon.io>
Fri, 25 May 2018 14:27:44 +0000 (16:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 26 May 2018 06:51:05 +0000 (08:51 +0200)
The limit of data read works only if all the data is in the
input buffer. Otherwise (if the data arrive in chunks), the
total amount of data is not taken in acount.

Only the current read data are compared to the expected amout
of data.

This patch must be backported from 1.9 to 1.6

src/hlua.c

index 727d664843c22695c5bc51fe17677f1dabe6f3ac..78d9cade72558fcbd1d8fee184fe84109ac15c6a 100644 (file)
@@ -1676,6 +1676,7 @@ __LJMP static int hlua_socket_receive_yield(struct lua_State *L, int status, lua
        struct stream_interface *si;
        struct stream *s;
        struct xref *peer;
+       int missing_bytes;
 
        /* Check if this lua stack is schedulable. */
        if (!hlua || !hlua->task)
@@ -1745,11 +1746,12 @@ __LJMP static int hlua_socket_receive_yield(struct lua_State *L, int status, lua
                if (nblk == 0) /* No data avalaible. */
                        goto connection_empty;
 
-               if (len1 > wanted) {
+               missing_bytes = wanted - socket->b.n;
+               if (len1 > missing_bytes) {
                        nblk = 1;
-                       len1 = wanted;
-               } if (nblk == 2 && len1 + len2 > wanted)
-                       len2 = wanted - len1;
+                       len1 = missing_bytes;
+               } if (nblk == 2 && len1 + len2 > missing_bytes)
+                       len2 = missing_bytes - len1;
        }
 
        len = len1;
@@ -1772,7 +1774,7 @@ __LJMP static int hlua_socket_receive_yield(struct lua_State *L, int status, lua
         */
        if (wanted == HLSR_READ_ALL)
                goto connection_empty;
-       else if (wanted >= 0 && len < wanted)
+       else if (wanted >= 0 && socket->b.n < wanted)
                goto connection_empty;
 
        /* Return result. */