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

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