From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Netfilter Development Mailinglist <netfilter-devel@vger.kernel.org>
Cc: Patrick McHardy <kaber@trash.net>
Subject: [PATCH] iptables: fix error reporting for missing/wrong arguments
Date: Sun, 12 Oct 2008 21:39:32 +0200 [thread overview]
Message-ID: <48F25274.5090107@netfilter.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 562 bytes --]
Hi,
I just noticed some problems in the iptables error reporting, the patch
attached should fix them. If nobody finds any problem on it, I'll push
it to git.
Some work to improve iptables error reporting would be nice, I'll see if
I can have a look into this issue. BTW, it would be nice to have some
kind of tool to automate the testing of command line interface. Thus, we
can ensure that the tool output remains consistent. I started some tool
for the conntrack-tools but it is still very simple.
--
"Los honestos son inadaptados sociales" -- Les Luthiers
[-- Attachment #2: x.patch --]
[-- Type: text/x-diff, Size: 2449 bytes --]
[PATCH] iptables: fix error reporting for missing/wrong arguments
This patch fixes a confusing error reporting when some arguments are
missing or the option passed is unknown.
According to man getopt_long:
"If getopt() finds an option character in argv that was not
included in optstring, or if it detects a missing option
argument, it returns '?' and sets the external variable
optopt to the actual option character."
Without the patch:
% iptables -I INPUT -m state --whatever
iptables v1.4.2-rc1: Unknown arg `(null)
% iptables -I INPUT -m state --state
iptables v1.4.2-rc1: Unknown arg `(null)
With the patch:
% iptables -I INPUT -m state --whatever
iptables v1.4.2-rc1: unknown option `--whatever'
Try `iptables -h' or 'iptables --help' for more information.
% iptables -I INPUT -m state --state
iptables v1.4.2-rc1: option `--state' requires an argument
Try `iptables -h' or 'iptables --help' for more information.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
diff --git a/ip6tables.c b/ip6tables.c
index 12298ca..9ce1074 100644
--- a/ip6tables.c
+++ b/ip6tables.c
@@ -1888,9 +1888,26 @@ int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t *handle)
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;
diff --git a/iptables.c b/iptables.c
index b927a11..d2b9081 100644
--- a/iptables.c
+++ b/iptables.c
@@ -1909,9 +1909,26 @@ int do_command(int argc, char *argv[], char **table, iptc_handle_t *handle)
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;
next reply other threads:[~2008-10-12 19:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-12 19:39 Pablo Neira Ayuso [this message]
2008-10-12 20:45 ` [PATCH] iptables: fix error reporting for missing/wrong arguments Jan Engelhardt
2008-10-13 11:01 ` Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48F25274.5090107@netfilter.org \
--to=pablo@netfilter.org \
--cc=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.