]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: channel: don't use co_set_data() to decrement output
authorWilly Tarreau <w@1wt.eu>
Mon, 28 Feb 2022 15:51:23 +0000 (16:51 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 28 Feb 2022 15:51:23 +0000 (16:51 +0100)
The use of co_set_data() should be strictly limited to setting the amount
of existing data to be transmitted. It ought not be used to decrement the
output after the data have left the buffer, because doing so involves
performing incorrect calculations using co_data() that still comprises
data that are not in the buffer anymore. Let's use c_rew() for this, which
is made exactly for this purpose, i.e. decrement c->output by as much as
requested. This is cleaner, faster, and will permit stricter checks.

include/haproxy/channel.h
src/hlua.c
src/stream_interface.c

index 8de8e17580c37f545a98ac15ff01232718564734..57e3d9853479e5cd443c73c66cfae4a329b40ec3 100644 (file)
@@ -1007,7 +1007,7 @@ static inline int32_t co_htx_remove_blk(struct channel *chn, struct htx *htx, st
        int32_t size = htx_get_blksz(blk);
 
        htx_remove_blk(htx, blk);
-       co_set_data(chn, co_data(chn) - size);
+       c_rew(chn, size);
 
        return size;
 }
index 8b42746d8266fc44eae7b3b173d672e82c87e7cd..a69adbd0b47914ae5ec6df6ad67779ea221c085d 100644 (file)
@@ -4991,7 +4991,7 @@ __LJMP static int hlua_applet_http_getline_yield(lua_State *L, int status, lua_K
                                break;
                }
 
-               co_set_data(req, co_data(req) - vlen);
+               c_rew(req, vlen);
                count -= vlen;
                if (sz == vlen)
                        blk = htx_remove_blk(htx, blk);
@@ -5081,7 +5081,7 @@ __LJMP static int hlua_applet_http_recv_yield(lua_State *L, int status, lua_KCon
                                break;
                }
 
-               co_set_data(req, co_data(req) - vlen);
+               c_rew(req, vlen);
                count -= vlen;
                if (len > 0)
                        len -= vlen;
index ecbd7b06d3699398d24a346d2a9b66dd9e60ed9a..4442b22295e15cd4ea27b01f39321a7215e24d46 100644 (file)
@@ -792,7 +792,7 @@ int si_cs_send(struct conn_stream *cs)
                ret = conn->mux->snd_buf(cs, &oc->buf, co_data(oc), send_flag);
                if (ret > 0) {
                        did_send = 1;
-                       co_set_data(oc, co_data(oc) - ret);
+                       c_rew(oc, ret);
                        c_realign_if_empty(oc);
 
                        if (!co_data(oc)) {