From 4e470fa34761085144640fb561a9ad26b2cde382 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Tue, 22 Oct 2019 12:25:28 +0200 Subject: xtables-restore: Unbreak *tables-restore Commit 3dc433b55bbfa ("xtables-restore: Fix --table parameter check") installed an error check which evaluated true in all cases as all callers of do_command callbacks pass a pointer to a table name already. Attached test case passed as it tested error condition only. Fix the whole mess by introducing a boolean to indicate whether a table parameter was seen already. Extend the test case to cover positive as well as negative behaviour and to test ebtables-restore and ip6tables-restore as well. Also add the required checking code to the latter since the original commit missed it. Fixes: 3dc433b55bbfa ("xtables-restore: Fix --table parameter check") Signed-off-by: Phil Sutter Acked-by: Pablo Neira Ayuso --- iptables/iptables.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'iptables/iptables.c') diff --git a/iptables/iptables.c b/iptables/iptables.c index d7a41321..544e8759 100644 --- a/iptables/iptables.c +++ b/iptables/iptables.c @@ -1217,6 +1217,7 @@ int do_command4(int argc, char *argv[], char **table, struct xtables_rule_match *matchp; struct xtables_target *t; unsigned long long cnt; + bool table_set = false; /* re-set optind to 0 in case do_command4 gets called * a second time */ @@ -1494,11 +1495,12 @@ int do_command4(int argc, char *argv[], char **table, if (cs.invert) xtables_error(PARAMETER_PROBLEM, "unexpected ! flag before --table"); - if (restore && *table) + if (restore && table_set) xtables_error(PARAMETER_PROBLEM, "The -t option (seen in line %u) cannot be used in %s.\n", line, xt_params->program_name); *table = optarg; + table_set = true; break; case 'x': -- cgit v1.2.3