Blame SOURCES/0002-xtables-restore-Fix-parser-feed-from-line-buffer.patch

6ef253
From 25af0fd3a7edd9a9aa5ed7ed63188456ee6389ef Mon Sep 17 00:00:00 2001
6ef253
From: Phil Sutter <phil@nwl.cc>
6ef253
Date: Wed, 4 Dec 2019 09:56:06 +0100
6ef253
Subject: [PATCH] xtables-restore: Fix parser feed from line buffer
6ef253
6ef253
When called with --noflush, xtables-restore would trip over chain lines:
6ef253
Parser uses strtok() to separate chain name, policy and counters which
6ef253
inserts nul-chars into the source string. Therefore strlen() can't be
6ef253
used anymore to find end of line. Fix this by caching line length before
6ef253
calling xtables_restore_parse_line().
6ef253
6ef253
Fixes: 09cb517949e69 ("xtables-restore: Improve performance of --noflush operation")
6ef253
Signed-off-by: Phil Sutter <phil@nwl.cc>
6ef253
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6ef253
(cherry picked from commit a103fbfadf4c17b8b12caa57eef72deaaa71a18c)
6ef253
Signed-off-by: Phil Sutter <psutter@redhat.com>
6ef253
---
6ef253
 .../testcases/ipt-restore/0010-noflush-new-chain_0     | 10 ++++++++++
6ef253
 iptables/xtables-restore.c                             |  4 +++-
6ef253
 2 files changed, 13 insertions(+), 1 deletion(-)
6ef253
 create mode 100755 iptables/tests/shell/testcases/ipt-restore/0010-noflush-new-chain_0
6ef253
6ef253
diff --git a/iptables/tests/shell/testcases/ipt-restore/0010-noflush-new-chain_0 b/iptables/tests/shell/testcases/ipt-restore/0010-noflush-new-chain_0
6ef253
new file mode 100755
6ef253
index 0000000000000..739e684a21183
6ef253
--- /dev/null
6ef253
+++ b/iptables/tests/shell/testcases/ipt-restore/0010-noflush-new-chain_0
6ef253
@@ -0,0 +1,10 @@
6ef253
+#!/bin/sh -e
6ef253
+
6ef253
+# assert input feed from buffer doesn't trip over
6ef253
+# added nul-chars from parsing chain line.
6ef253
+
6ef253
+$XT_MULTI iptables-restore --noflush <
6ef253
+*filter
6ef253
+:foobar - [0:0]
6ef253
+-A foobar -j ACCEPT
6ef253
+COMMIT
6ef253
diff --git a/iptables/xtables-restore.c b/iptables/xtables-restore.c
6ef253
index 2f0fe7d439d94..dd907e0b8ddd5 100644
6ef253
--- a/iptables/xtables-restore.c
6ef253
+++ b/iptables/xtables-restore.c
6ef253
@@ -327,10 +327,12 @@ void xtables_restore_parse(struct nft_handle *h,
6ef253
 	line = 0;
6ef253
 	ptr = preload_buffer;
6ef253
 	while (*ptr) {
6ef253
+		size_t len = strlen(ptr);
6ef253
+
6ef253
 		h->error.lineno = ++line;
6ef253
 		DEBUGP("%s: buffered line %d: '%s'\n", __func__, line, ptr);
6ef253
 		xtables_restore_parse_line(h, p, &state, ptr);
6ef253
-		ptr += strlen(ptr) + 1;
6ef253
+		ptr += len + 1;
6ef253
 	}
6ef253
 	if (*buffer) {
6ef253
 		h->error.lineno = ++line;
6ef253
-- 
6ef253
2.24.0
6ef253