]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
iptables: fix longopt reecognition and workaround getopt(3) behavior
authorJan Engelhardt <jengelh@medozas.de>
Mon, 15 Nov 2010 12:19:48 +0000 (13:19 +0100)
committerJan Engelhardt <jengelh@medozas.de>
Mon, 15 Nov 2010 12:19:48 +0000 (13:19 +0100)
* On the first call to getopt, opts was NULL, so long options would
not be recognized until a match/target was loaded.

Whacky getopt behavior:

* If the longopts parameter is NULL, getopt fails to recognize unknown
options, such that `iptables-multi main --append` will print a garbage
help message ("main needs an argument").

* If the longopts parameter is NULL on the first call, but not on
subsequent calls, it completely screws up option parsing, taking
the --dport in `iptables-multi main -A INPUT -p tcp --dport 1000`
as --destination instead, but not accepting "--destination 1.2.3.4"
either.

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
ip6tables.c
iptables.c
xtables.c

index 150893d48ce4b86dfdc0cf698b0809ec34146b6b..8318f910a9067a52bd856b9b761a6f829f490132 100644 (file)
@@ -147,6 +147,7 @@ void ip6tables_exit_error(enum xtables_exittype status, const char *msg, ...) __
 struct xtables_globals ip6tables_globals = {
        .option_offset = 0,
        .program_version = IPTABLES_VERSION,
+       .opts = original_opts,
        .orig_opts = original_opts,
        .exit_err = ip6tables_exit_error,
 };
index 4c8bd773b160f70da978178f8f7f67ef03680184..c800fffd1d200ff4f0005df2abf40cf18c8c64f6 100644 (file)
@@ -147,6 +147,7 @@ void iptables_exit_error(enum xtables_exittype status, const char *msg, ...) __a
 struct xtables_globals iptables_globals = {
        .option_offset = 0,
        .program_version = IPTABLES_VERSION,
+       .opts = original_opts,
        .orig_opts = original_opts,
        .exit_err = iptables_exit_error,
 };
index 7658038cdb2e167fc472ce22b147c4506f87b6de..d0aa868876831b62ac61f7edb88c56fec1c51fbb 100644 (file)
--- a/xtables.c
+++ b/xtables.c
@@ -75,7 +75,8 @@ void basic_exit_err(enum xtables_exittype status, const char *msg, ...)
 
 void xtables_free_opts(int unused)
 {
-       free(xt_params->opts);
+       if (xt_params->opts != xt_params->orig_opts)
+               free(xt_params->opts);
 }
 
 struct option *xtables_merge_options(struct option *orig_opts,