From 59e8114c6792242e80785f4461d5e663fb9a3d64 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Mon, 15 Nov 2010 13:19:48 +0100 Subject: iptables: fix longopt reecognition and workaround getopt(3) behavior * 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 --- xtables.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'xtables.c') diff --git a/xtables.c b/xtables.c index 7658038c..d0aa8688 100644 --- 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, -- cgit v1.2.3