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

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