Blame SOURCES/0028-json-Work-around-segfault-when-encountering-xt-stmt.patch

9ff721
From 48c743edbd41470149a5ac58c350b47cb80fb9eb Mon Sep 17 00:00:00 2001
9ff721
From: Phil Sutter <phil@nwl.cc>
9ff721
Date: Wed, 24 Oct 2018 21:14:37 +0200
9ff721
Subject: [PATCH] json: Work around segfault when encountering xt stmt
9ff721
9ff721
When trying to convert an xt stmt into JSON, print() callback was
9ff721
called. Though the code in src/xt.c does not respect output_fp,
9ff721
therefore buffer wasn't filled as expected making libjansson to puke:
9ff721
9ff721
| # nft -j list ruleset
9ff721
| warning: stmt ops xt have no json callback
9ff721
| nft: json.c:169: stmt_print_json: Assertion `__out' failed.
9ff721
| Aborted (core dumped)
9ff721
9ff721
Avoid this by detecting xt stmt ops and returning a stub.
9ff721
9ff721
Signed-off-by: Phil Sutter <phil@nwl.cc>
9ff721
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9ff721
(cherry picked from commit b849b0dfd9f3aecff5617bc60d5852ef36c3d494)
9ff721
9ff721
Conflicts:
9ff721
	doc/libnftables-json.adoc
9ff721
-> Patches adding this man page are missing entirely.
9ff721
9ff721
Signed-off-by: Phil Sutter <psutter@redhat.com>
9ff721
---
9ff721
 src/json.c | 6 ++++++
9ff721
 1 file changed, 6 insertions(+)
9ff721
9ff721
diff --git a/src/json.c b/src/json.c
9ff721
index 98581a3c2a3e4..f74afd5a7292e 100644
9ff721
--- a/src/json.c
9ff721
+++ b/src/json.c
9ff721
@@ -165,6 +165,12 @@ static json_t *stmt_print_json(const struct stmt *stmt, struct output_ctx *octx)
9ff721
 	char buf[1024];
9ff721
 	FILE *fp;
9ff721
 
9ff721
+	/* XXX: Can't be supported at this point:
9ff721
+	 * xt_stmt_xlate() ignores output_fp.
9ff721
+	 */
9ff721
+	if (stmt->ops->type == STMT_XT)
9ff721
+		return json_pack("{s:n}", "xt");
9ff721
+
9ff721
 	if (stmt->ops->json)
9ff721
 		return stmt->ops->json(stmt, octx);
9ff721
 
9ff721
-- 
bacbc8
2.21.0
9ff721