iptables: fix error reporting with wrong/missing arguments
This patch fixes wrong error reporting when arguments are missing:
# iptables -I INPUT -m state --state
iptables v1.4.2-rc1: Unknown arg `(null)'
Try `iptables -h' or 'iptables --help' for more information.
or wrong:
# iptables -I INPUT -m state --xyz
iptables v1.4.2-rc1: Unknown arg `(null)'
Try `iptables -h' or 'iptables --help' for more information.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
diff --git a/iptables.c b/iptables.c
index 2c6b4dc..b75df87 100644
--- a/iptables.c
+++ b/iptables.c
@@ -1909,9 +1909,26 @@
optind--;
continue;
}
- if (!m)
+ if (!m) {
+ if (c == '?') {
+ if (optopt) {
+ exit_error(
+ PARAMETER_PROBLEM,
+ "option `%s' "
+ "requires an "
+ "argument",
+ argv[optind-1]);
+ } else {
+ exit_error(
+ PARAMETER_PROBLEM,
+ "unknown option "
+ "`%s'",
+ argv[optind-1]);
+ }
+ }
exit_error(PARAMETER_PROBLEM,
"Unknown arg `%s'", optarg);
+ }
}
}
invert = FALSE;