diff mbox series

[iptables] xtables: Accept --wait in iptables-nft-restore

Message ID 20180905171440.21530-1-phil@nwl.cc
State Accepted
Delegated to: Pablo Neira
Headers show
Series [iptables] xtables: Accept --wait in iptables-nft-restore | expand

Commit Message

Phil Sutter Sept. 5, 2018, 5:14 p.m. UTC
Passing --wait option to iptables-nft-restore led to program abort
because the flag parameter was not skipped. Mimick iptables-restore
behaviour when encountering --wait or --wait-interval options (but still
ignore the parameter).

Fixes: b9d7b49d84bc2 ("xtables-compat: restore: sync options with iptables-restore")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 .../testcases/ipt-restore/0002-parameters_0   | 21 +++++++++++++++++++
 iptables/xtables-restore.c                    |  2 ++
 2 files changed, 23 insertions(+)
 create mode 100755 iptables/tests/shell/testcases/ipt-restore/0002-parameters_0

Comments

Florian Westphal Sept. 10, 2018, 1:46 p.m. UTC | #1
Phil Sutter <phil@nwl.cc> wrote:
> Passing --wait option to iptables-nft-restore led to program abort
> because the flag parameter was not skipped. Mimick iptables-restore
> behaviour when encountering --wait or --wait-interval options (but still
> ignore the parameter).

Thanks for submitting a test case too, applied.
diff mbox series

Patch

diff --git a/iptables/tests/shell/testcases/ipt-restore/0002-parameters_0 b/iptables/tests/shell/testcases/ipt-restore/0002-parameters_0
new file mode 100755
index 0000000000000..5c8748ec765b2
--- /dev/null
+++ b/iptables/tests/shell/testcases/ipt-restore/0002-parameters_0
@@ -0,0 +1,21 @@ 
+#!/bin/sh
+
+set -e
+
+# make sure wait and wait-interval options are accepted
+
+clean_tempfile()
+{
+	if [ -n "${tmpfile}" ]; then
+		rm -f "${tmpfile}"
+	fi
+}
+
+trap clean_tempfile EXIT
+
+tmpfile=$(mktemp) || exit 1
+
+$XT_MULTI iptables-save -f $tmpfile
+$XT_MULTI iptables-restore $tmpfile
+$XT_MULTI iptables-restore -w 5 $tmpfile
+$XT_MULTI iptables-restore -w 5 -W 1 $tmpfile
diff --git a/iptables/xtables-restore.c b/iptables/xtables-restore.c
index d2b7920869344..3274543677329 100644
--- a/iptables/xtables-restore.c
+++ b/iptables/xtables-restore.c
@@ -415,6 +415,8 @@  xtables_restore_main(int family, const char *progname, int argc, char *argv[])
 				break;
 			case 'w': /* fallthrough.  Ignored by xt-restore */
 			case 'W':
+				if (!optarg && xs_has_arg(argc, argv))
+					optind++;
 				break;
 			default:
 				fprintf(stderr,