]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xtables-restore: Allow lines without trailing newline character
authorPhil Sutter <phil@nwl.cc>
Wed, 18 Sep 2019 13:39:44 +0000 (15:39 +0200)
committerPhil Sutter <phil@nwl.cc>
Wed, 6 Nov 2019 12:41:56 +0000 (13:41 +0100)
Old code in add_param_to_argv() assumed the input line would always end
with a newline character. Without it, the last word of input wasn't
recognized. Fix this by adding a final check for param.len (indicating
leftover data in buffer).

In line parsing code itself, only COMMIT line check required presence of
trailing newline. The replaced conditional is not 100% accurate as it
allows for characters after newline to be present, but since fgets() is
used this shouldn't happen anyway.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
iptables/xshared.c
iptables/xtables-restore.c

index 2a0077d9da846c7bc992359ffd46cf8818813cbe..16c58914e59a5a3e4f14807d30e372c4d7096bcc 100644 (file)
@@ -530,6 +530,10 @@ void add_param_to_argv(struct argv_store *store, char *parsestart, int line)
                param.len = 0;
                quoted = 0;
        }
+       if (param.len) {
+               param.buffer[param.len] = '\0';
+               add_argv(store, param.buffer, 0);
+       }
 }
 
 #ifdef DEBUG
index 83e05102769a76b1839bf4f6ebd615b5e11ca007..5a534ca227379eff5f165e0058fcb53f3df56963 100644 (file)
@@ -88,7 +88,9 @@ static void xtables_restore_parse_line(struct nft_handle *h,
                if (verbose)
                        fputs(buffer, stdout);
                return;
-       } else if ((strcmp(buffer, "COMMIT\n") == 0) && state->in_table) {
+       } else if (state->in_table &&
+                  (strncmp(buffer, "COMMIT", 6) == 0) &&
+                  (buffer[6] == '\0' || buffer[6] == '\n')) {
                if (!p->testing) {
                        /* Commit per table, although we support
                         * global commit at once, stick by now to