iptables: option parsing fixes
The following changes since commit a905ea5c97149da9d76cd278b0447e3316087a45:
Merge branch 'master' of git://dev.medozas.de/iptables into m2 (2010-11-15 14:39:50 +0100)
are available in the git repository at:
git://dev.medozas.de/iptables master
Jan Engelhardt (2):
iptables: reset options at the start of each command
iptables: do not emit orig_opts twice
ip6tables.c | 2 +- iptables.c | 2 +- xtables.c | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-)
PATCH 1/2 iptables: reset options at the start of each command
For each new command, iptables is supposed to start afresh with a blank option set (opts) that only contains the program-specific options (orig_opts), without any extension options. We failed to restore this pointer (in function do_command) after the previous free call in xtables_free_opts.
--- ip6tables.c | 2 +- iptables.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
ip6tables.c +1 -1
@@ -147,7 +147,6 @@ 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, };
@@ -1335,6 +1334,7 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handdemand-load a protocol. */ opterr =0 ; + opts = xt_params->orig_opts;while ((c =getopt_long (argc, argv,"-A:D:R:I:L::S::M:F::Z::N:X::E:P:Vh::o:p:s:d:j:i:bvnt:m:xc:g:" , opts,NULL )) !=-1 ) {
iptables.c +1 -1
@@ -147,7 +147,6 @@ void iptables_exit_error(enum xtables_exittype status, const char *msg, ...) __astruct xtables_globals iptables_globals = { .option_offset =0 , .program_version =IPTABLES_VERSION , - .opts = original_opts, .orig_opts = original_opts, .exit_err = iptables_exit_error, };
@@ -1358,6 +1357,7 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handledemand-load a protocol. */ opterr =0 ; + opts = xt_params->orig_opts;while ((c =getopt_long (argc, argv,"-A:D:R:I:L::S::M:F::Z::N:X::E:P:Vh::o:p:s:d:j:i:fbvnt:m:xc:g:" , opts,NULL )) !=-1 ) {
Signature · 1 line
1.7.1
PATCH 2/2 iptables: do not emit orig_opts twice
In reply to Jan EngelhardtThis just happened to cross my eye; there was no error, but fixing this up saves a pitfall, and some memory.
--- xtables.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
xtables.c +4 -0
@@ -103,6 +103,10 @@ struct option *xtables_merge_options(struct option *orig_opts,memcpy (merge, orig_opts,sizeof (*mp) * num_oold); mp = merge + num_oold; +/* Since @opts also has @orig_opts already, skip the entries */ + oldopts += num_oold; + num_old -= num_oold; +/* Second, the new options */ xt_params->option_offset +=256 ; *option_offset = xt_params->option_offset;
Signature · 1 line
1.7.1