]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: lua: Check argument type to convert it to IP mask in arg validation
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 7 Aug 2020 07:11:22 +0000 (09:11 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 7 Aug 2020 12:25:31 +0000 (14:25 +0200)
In hlua_lua2arg_check() function, before converting an argument to an IPv4 or
IPv6 mask, we must be sure to have an integer or a string argument (ARGT_SINT or
ARGT_STR).

This patch must be backported to all supported versions.

src/hlua.c

index f99bdf9d2059b4f33b6cdc9af427492e38d5af3a..f31f318a17108531cf2f584aee850d6704e95b3d 100644 (file)
@@ -752,11 +752,17 @@ __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp,
                        break;
 
                case ARGT_MSK4:
-                       memcpy(trash.area, argp[idx].data.str.area,
-                              argp[idx].data.str.data);
-                       trash.area[argp[idx].data.str.data] = 0;
-                       if (!str2mask(trash.area, &argp[idx].data.ipv4))
-                               WILL_LJMP(luaL_argerror(L, first + idx, "invalid IPv4 mask"));
+                       if (argp[idx].type == ARGT_SINT)
+                               len2mask4(argp[idx].data.sint, &argp[idx].data.ipv4);
+                       else if (argp[idx].type == ARGT_STR) {
+                               memcpy(trash.area, argp[idx].data.str.area,
+                                      argp[idx].data.str.data);
+                               trash.area[argp[idx].data.str.data] = 0;
+                               if (!str2mask(trash.area, &argp[idx].data.ipv4))
+                                       WILL_LJMP(luaL_argerror(L, first + idx, "invalid IPv4 mask"));
+                       }
+                       else
+                               WILL_LJMP(luaL_argerror(L, first + idx, "integer or string expected"));
                        argp[idx].type = ARGT_MSK4;
                        break;
 
@@ -772,11 +778,17 @@ __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp,
                        break;
 
                case ARGT_MSK6:
-                       memcpy(trash.area, argp[idx].data.str.area,
-                              argp[idx].data.str.data);
-                       trash.area[argp[idx].data.str.data] = 0;
-                       if (!str2mask6(trash.area, &argp[idx].data.ipv6))
-                               WILL_LJMP(luaL_argerror(L, first + idx, "invalid IPv6 mask"));
+                       if (argp[idx].type == ARGT_SINT)
+                               len2mask6(argp[idx].data.sint, &argp[idx].data.ipv6);
+                       else if (argp[idx].type == ARGT_STR) {
+                               memcpy(trash.area, argp[idx].data.str.area,
+                                      argp[idx].data.str.data);
+                               trash.area[argp[idx].data.str.data] = 0;
+                               if (!str2mask6(trash.area, &argp[idx].data.ipv6))
+                                       WILL_LJMP(luaL_argerror(L, first + idx, "invalid IPv6 mask"));
+                       }
+                       else
+                               WILL_LJMP(luaL_argerror(L, first + idx, "integer or string expected"));
                        argp[idx].type = ARGT_MSK6;
                        break;