BUG/MINOR: lua: Check argument type to convert it to IP mask in arg validation

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.

(cherry picked from commit e663a6e326c3d4d465d5aa66e4fbe3acde69aac3)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 2ef95fa486eae674cb32c491c7f5ca5da3299fee)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 1f02e529ad337243931edb33ce6777b6f3a1c3a7)
Signed-off-by: Willy Tarreau <w@1wt.eu>
diff --git a/src/hlua.c b/src/hlua.c
index 9eaa10b..1e70a4b 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -765,11 +765,17 @@
 			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;
 
@@ -785,11 +791,17 @@
 			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;