From: Phil Sutter Date: Wed, 4 Dec 2019 08:56:06 +0000 (+0100) Subject: xtables-restore: Fix parser feed from line buffer X-Git-Tag: v1.8.5~88 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a103fbfadf4c17b8b12caa57eef72deaaa71a18c;p=thirdparty%2Fiptables.git xtables-restore: Fix parser feed from line buffer When called with --noflush, xtables-restore would trip over chain lines: Parser uses strtok() to separate chain name, policy and counters which inserts nul-chars into the source string. Therefore strlen() can't be used anymore to find end of line. Fix this by caching line length before calling xtables_restore_parse_line(). Fixes: 09cb517949e69 ("xtables-restore: Improve performance of --noflush operation") Signed-off-by: Phil Sutter Acked-by: Pablo Neira Ayuso --- 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 new file mode 100755 index 00000000..739e684a --- /dev/null +++ b/iptables/tests/shell/testcases/ipt-restore/0010-noflush-new-chain_0 @@ -0,0 +1,10 @@ +#!/bin/sh -e + +# assert input feed from buffer doesn't trip over +# added nul-chars from parsing chain line. + +$XT_MULTI iptables-restore --noflush <error.lineno = ++line; DEBUGP("%s: buffered line %d: '%s'\n", __func__, line, ptr); xtables_restore_parse_line(h, p, &state, ptr); - ptr += strlen(ptr) + 1; + ptr += len + 1; } if (*buffer) { h->error.lineno = ++line;