]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: lua: Duplicate map name to load it when a new Map object is created
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 6 Aug 2020 06:40:09 +0000 (08:40 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 7 Aug 2020 12:24:30 +0000 (14:24 +0200)
When a new map is created, the sample_load_map() function is called. To do so,
an argument array is created with the name as first argument. Because it is a
lua string, owned by the lua, it must be duplicated. The sample_load_map()
function will convert this argument to a map. In theory, after the conversion,
it must release the original string. It is not performed for now and it is a bug
that will be fixed in the next commit.

This patch may be backported to all supported versions, most probably as far as
2.1 only. But it must be backported with the next commit "BUG/MINOR: arg: Fix
leaks during arguments validation for fetches/converters".

src/hlua.c

index 844a5ec9da1167b4f3f4a6f3069ef0f73e37e417..8bc8319446bf0eba809706b8f8c6f650778d8a11 100644 (file)
@@ -1512,7 +1512,9 @@ __LJMP static int hlua_map_new(struct lua_State *L)
 
        /* fill fake args. */
        args[0].type = ARGT_STR;
-       args[0].data.str.area = (char *)fn;
+       args[0].data.str.area = strdup(fn);
+       args[0].data.str.data = strlen(fn);
+       args[0].data.str.size = args[0].data.str.data+1;
        args[1].type = ARGT_STOP;
 
        /* load the map. */
@@ -1524,6 +1526,7 @@ __LJMP static int hlua_map_new(struct lua_State *L)
                lua_pushfstring(L, "'new': %s.", err);
                lua_concat(L, 2);
                free(err);
+               free(args[0].data.str.area);
                WILL_LJMP(lua_error(L));
        }