]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
parser_json: use stdin buffer if available
authorPablo Neira Ayuso <pablo@netfilter.org>
Tue, 9 Jul 2024 14:59:52 +0000 (16:59 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 23 Jan 2025 00:35:36 +0000 (01:35 +0100)
commit e48f32701ff65d522c2f29f34bf4f3ce8e562057 upstream.

Since 5c2b2b0a2ba7 ("src: error reporting with -f and read from stdin")
stdin is stored in a buffer, update json support to use it instead of
reading from /dev/stdin.

Some systems do not provide /dev/stdin symlink to /proc/self/fd/0
according to reporter (that mentions Yocto Linux as example).

Fixes: 935f82e7dd49 ("Support 'nft -f -' to read from stdin")
Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/libnftables.c
src/parser_json.c

index a0e2488788dd20fd0cbcbd6732452c3aff1db6cb..8c532dc2c22b764fe045dd3223aa84f1a0640d0d 100644 (file)
@@ -784,8 +784,7 @@ int nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename)
        if (!strcmp(filename, "-"))
                filename = "/dev/stdin";
 
-       if (!strcmp(filename, "/dev/stdin") &&
-           !nft_output_json(&nft->output))
+       if (!strcmp(filename, "/dev/stdin"))
                nft->stdin_buf = stdin_to_buffer();
 
        if (nft->optimize_flags) {
index 97e1172c362e0f09cbc0fb97dcfa2dc66d419226..461d9d3119da1ebab80c846d7286f49775abd4dc 100644 (file)
@@ -4180,6 +4180,13 @@ int nft_parse_json_filename(struct nft_ctx *nft, const char *filename,
        json_error_t err;
        int ret;
 
+       if (nft->stdin_buf) {
+               json_indesc.type = INDESC_STDIN;
+               json_indesc.name = "/dev/stdin";
+
+               return nft_parse_json_buffer(nft, nft->stdin_buf, msgs, cmds);
+       }
+
        json_indesc.type = INDESC_FILE;
        json_indesc.name = filename;