]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: hlua: hlua_channel_insert_data() behavior conflicts with documentation
authorAurelien DARRAGON <adarragon@haproxy.com>
Tue, 4 Oct 2022 10:16:05 +0000 (12:16 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 5 Oct 2022 09:03:56 +0000 (11:03 +0200)
Channel.insert(channel, string, [,offset]):

When no offset is provided, hlua_channel_insert_data() inserts
string at the end of incoming data.

This behavior conflicts with the documentation that explicitly says
that the default behavior is to insert the string in front of incoming data.

This patch fixes hlua_channel_insert_data() behavior so that it fully
complies with the documentation.

Thanks to Smackd0wn for noticing it.

This could be backported to 2.6 and 2.5

src/hlua.c

index ee48f5c92fee7b7467f2e3faa7e3befc91cc6387..19932a5b121635ffd2344882ec2dc0457fea040a 100644 (file)
@@ -3573,7 +3573,7 @@ __LJMP static int hlua_channel_prepend(lua_State *L)
 }
 
 /* Inserts a given amount of input data at the given offset by a string
- * content. By default the string is appended at the end of input data. It
+ * content. By default the string is appended in front of input data. It
  * returns the length of the written string, or -1 if the channel is closed or
  * if the buffer size is too little for the data.
  *
@@ -3599,13 +3599,13 @@ __LJMP static int hlua_channel_insert_data(lua_State *L)
        if (filter && !hlua_filter_from_payload(filter))
                WILL_LJMP(lua_error(L));
 
-       offset = input + output;
+       offset = output;
        if (lua_gettop(L) > 2) {
                offset = MAY_LJMP(luaL_checkinteger(L, 3));
                if (offset < 0)
                        offset = MAX(0, (int)input + offset);
                offset += output;
-               if (offset < output || offset > output + input) {
+               if (offset > output + input) {
                        lua_pushfstring(L, "offset out of range.");
                        WILL_LJMP(lua_error(L));
                }