Blame SOURCES/0017-src-bail-out-when-exporting-ruleset-with-unsupported.patch

ad45ff
From 032a1808c1abb70004703f57c2d1625a099beca3 Mon Sep 17 00:00:00 2001
ad45ff
From: Phil Sutter <psutter@redhat.com>
ad45ff
Date: Fri, 15 Mar 2019 12:59:19 +0100
ad45ff
Subject: [PATCH] src: bail out when exporting ruleset with unsupported output
ad45ff
ad45ff
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1646336
ad45ff
Upstream Status: nftables commit a340aa6ca6cd0
ad45ff
Conflicts:
ad45ff
* Dropped changes to import command which doesn't exist in RHEL7.
ad45ff
* Changes to parser_bison.y applied manually. Major conflicts due to
ad45ff
  missing commit 2fa54d8a49352 ("src: Add import command for low level
ad45ff
  json").
ad45ff
* Adjusted to missing commit 2fa54d8a49352 ("src: Add import command for
ad45ff
  low level json").
ad45ff
ad45ff
commit a340aa6ca6cd08ae173fbb95cd3e65807264df07
ad45ff
Author: Pablo Neira Ayuso <pablo@netfilter.org>
ad45ff
Date:   Thu Feb 15 17:22:16 2018 +0100
ad45ff
ad45ff
    src: bail out when exporting ruleset with unsupported output
ad45ff
ad45ff
    Display error message and propagate error to shell when running command
ad45ff
    with unsupported output:
ad45ff
ad45ff
     # nft export ruleset json
ad45ff
     Error: this output type is not supported
ad45ff
     export ruleset json
ad45ff
     ^^^^^^^^^^^^^^^^^^^^
ad45ff
     # echo $?
ad45ff
     1
ad45ff
ad45ff
    When displaying the output in json using the low-level VM
ad45ff
    representation, it shows:
ad45ff
ad45ff
     # nft export ruleset vm json
ad45ff
     ... low-level VM json output
ad45ff
     # echo $?
ad45ff
     0
ad45ff
ad45ff
    While at it, do the same with obsoleted XML output.
ad45ff
ad45ff
    Fixes: https://bugzilla.netfilter.org/show_bug.cgi?id=1224
ad45ff
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
ad45ff
---
ad45ff
 include/nftables.h | 2 ++
ad45ff
 src/evaluate.c     | 3 +++
ad45ff
 src/parser_bison.y | 4 ++--
ad45ff
 3 files changed, 7 insertions(+), 2 deletions(-)
ad45ff
ad45ff
diff --git a/include/nftables.h b/include/nftables.h
ad45ff
index 01d72a8..0abbcaf 100644
ad45ff
--- a/include/nftables.h
ad45ff
+++ b/include/nftables.h
ad45ff
@@ -154,4 +154,6 @@ int nft_print(struct output_ctx *octx, const char *fmt, ...)
ad45ff
 int nft_gmp_print(struct output_ctx *octx, const char *fmt, ...)
ad45ff
 	__attribute__((format(printf, 2, 0)));
ad45ff
 
ad45ff
+#define __NFT_OUTPUT_NOTSUPP	UINT_MAX
ad45ff
+
ad45ff
 #endif /* NFTABLES_NFTABLES_H */
ad45ff
diff --git a/src/evaluate.c b/src/evaluate.c
ad45ff
index ab1347f..c8a98f1 100644
ad45ff
--- a/src/evaluate.c
ad45ff
+++ b/src/evaluate.c
ad45ff
@@ -3426,6 +3426,9 @@ static int cmd_evaluate_monitor(struct eval_ctx *ctx, struct cmd *cmd)
ad45ff
 
ad45ff
 static int cmd_evaluate_export(struct eval_ctx *ctx, struct cmd *cmd)
ad45ff
 {
ad45ff
+	if (cmd->export->format == __NFT_OUTPUT_NOTSUPP)
ad45ff
+		return cmd_error(ctx, "this output type is not supported");
ad45ff
+
ad45ff
 	return cache_update(ctx->nf_sock, ctx->cache, cmd->op, ctx->msgs,
ad45ff
 			    ctx->debug_mask & DEBUG_NETLINK, ctx->octx);
ad45ff
 }
ad45ff
diff --git a/src/parser_bison.y b/src/parser_bison.y
ad45ff
index f9878ba..e87669e 100644
ad45ff
--- a/src/parser_bison.y
ad45ff
+++ b/src/parser_bison.y
ad45ff
@@ -1204,8 +1204,8 @@ monitor_format		:	/* empty */	{ $$ = NFTNL_OUTPUT_DEFAULT; }
ad45ff
 			|	export_format
ad45ff
 			;
ad45ff
 
ad45ff
-export_format		: 	XML 		{ $$ = NFTNL_OUTPUT_XML; }
ad45ff
-			|	JSON		{ $$ = NFTNL_OUTPUT_JSON; }
ad45ff
+export_format		: 	XML 		{ $$ = __NFT_OUTPUT_NOTSUPP; }
ad45ff
+			|	JSON		{ $$ = __NFT_OUTPUT_NOTSUPP; }
ad45ff
 			;
ad45ff
 
ad45ff
 describe_cmd		:	primary_expr
ad45ff
-- 
ad45ff
1.8.3.1
ad45ff