BUG/MINOR: lua: Check argument type to convert it to IPv4/IPv6 arg validation
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 7 Aug 2020 07:07:26 +0000 (09:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 11 Aug 2020 09:37:13 +0000 (11:37 +0200)
In hlua_lua2arg_check() function, before converting a string to an IP address,
we must be to sure to have a string argument (ARGT_STR).

This patch must be backported to all supported versions.

(cherry picked from commit 8e09ac8592cb35e11bff0f821db19369e0941e35)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit af6bd3010aac6565e98e61d6bb1ea973f0f271d4)
Signed-off-by: Willy Tarreau <w@1wt.eu>

src/hlua.c

index dd65e22..8f1fdf6 100644 (file)
@@ -744,6 +744,8 @@ __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp,
                        break;
 
                case ARGT_IPV4:
+                       if (argp[idx].type != ARGT_STR)
+                               WILL_LJMP(luaL_argerror(L, first + idx, "string expected"));
                        memcpy(trash.area, argp[idx].data.str.area,
                               argp[idx].data.str.data);
                        trash.area[argp[idx].data.str.data] = 0;
@@ -762,6 +764,8 @@ __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp,
                        break;
 
                case ARGT_IPV6:
+                       if (argp[idx].type != ARGT_STR)
+                               WILL_LJMP(luaL_argerror(L, first + idx, "string expected"));
                        memcpy(trash.area, argp[idx].data.str.area,
                               argp[idx].data.str.data);
                        trash.area[argp[idx].data.str.data] = 0;