From 45989e8fbec52fcbafa5ae9917fc2a0d62e3640d Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Tue, 22 Oct 2019 22:49:29 +0200 Subject: xshared: Share a common add_command() implementation The shared definition of cmdflags is a super set of the previous one in xtables-arp.c so while not being identical, they're compatible. Avoid accidental array overstep in cmd2char() by incrementing an index variable and checking its final value before using it as such. Signed-off-by: Phil Sutter Acked-by: Pablo Neira Ayuso --- iptables/ip6tables.c | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'iptables/ip6tables.c') diff --git a/iptables/ip6tables.c b/iptables/ip6tables.c index ee463c95..9a9d71f1 100644 --- a/iptables/ip6tables.c +++ b/iptables/ip6tables.c @@ -69,8 +69,6 @@ #define CMD_ZERO_NUM 0x2000U #define CMD_CHECK 0x4000U #define NUMBER_OF_CMD 16 -static const char cmdflags[] = { 'I', 'D', 'D', 'R', 'A', 'L', 'F', 'Z', - 'N', 'X', 'P', 'E', 'S', 'Z', 'C' }; #define NUMBER_OF_OPT ARRAY_SIZE(optflags) static const char optflags[] @@ -336,27 +334,6 @@ opt2char(int option) return *ptr; } -static char -cmd2char(int option) -{ - const char *ptr; - for (ptr = cmdflags; option > 1; option >>= 1, ptr++); - - return *ptr; -} - -static void -add_command(unsigned int *cmd, const int newcmd, const int othercmds, - int invert) -{ - if (invert) - xtables_error(PARAMETER_PROBLEM, "unexpected '!' flag"); - if (*cmd & (~othercmds)) - xtables_error(PARAMETER_PROBLEM, "Cannot use -%c with -%c\n", - cmd2char(newcmd), cmd2char(*cmd & (~othercmds))); - *cmd |= newcmd; -} - /* * All functions starting with "parse" should succeed, otherwise * the program fails. -- cgit v1.2.3