Blame SOURCES/0063-parser_json-Fix-error-reporting-for-invalid-syntax.patch

8ff5ad
From 8cb078a2f9f69259325c10f479c198349ef01ef2 Mon Sep 17 00:00:00 2001
8ff5ad
From: Phil Sutter <psutter@redhat.com>
8ff5ad
Date: Wed, 6 Oct 2021 17:24:44 +0200
8ff5ad
Subject: [PATCH] parser_json: Fix error reporting for invalid syntax
8ff5ad
8ff5ad
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1994141
8ff5ad
Upstream Status: nftables commit 9fe5d1bc18cfa
8ff5ad
8ff5ad
commit 9fe5d1bc18cfaed2ecf717e3dd9a97ff5b0e183c
8ff5ad
Author: Phil Sutter <phil@nwl.cc>
8ff5ad
Date:   Wed Sep 1 16:41:44 2021 +0200
8ff5ad
8ff5ad
    parser_json: Fix error reporting for invalid syntax
8ff5ad
8ff5ad
    Errors emitted by the JSON parser caused BUG() in erec_print() due to
8ff5ad
    input descriptor values being bogus.
8ff5ad
8ff5ad
    Due to lack of 'include' support, JSON parser uses a single input
8ff5ad
    descriptor only and it lived inside the json_ctx object on stack of
8ff5ad
    nft_parse_json_*() functions.
8ff5ad
8ff5ad
    By the time errors are printed though, that scope is not valid anymore.
8ff5ad
    Move the static input descriptor object to avoid this.
8ff5ad
8ff5ad
    Fixes: 586ad210368b7 ("libnftables: Implement JSON parser")
8ff5ad
    Signed-off-by: Phil Sutter <phil@nwl.cc>
8ff5ad
---
8ff5ad
 src/parser_json.c | 18 ++++++++----------
8ff5ad
 1 file changed, 8 insertions(+), 10 deletions(-)
8ff5ad
8ff5ad
diff --git a/src/parser_json.c b/src/parser_json.c
8ff5ad
index a069a89..ef4d4fb 100644
8ff5ad
--- a/src/parser_json.c
8ff5ad
+++ b/src/parser_json.c
8ff5ad
@@ -44,7 +44,6 @@
8ff5ad
 #define CTX_F_CONCAT	(1 << 8)	/* inside concat_expr */
8ff5ad
 
8ff5ad
 struct json_ctx {
8ff5ad
-	struct input_descriptor indesc;
8ff5ad
 	struct nft_ctx *nft;
8ff5ad
 	struct list_head *msgs;
8ff5ad
 	struct list_head *cmds;
8ff5ad
@@ -107,11 +106,12 @@ static struct stmt *json_parse_stmt(struct json_ctx *ctx, json_t *root);
8ff5ad
 /* parsing helpers */
8ff5ad
 
8ff5ad
 const struct location *int_loc = &internal_location;
8ff5ad
+static struct input_descriptor json_indesc;
8ff5ad
 
8ff5ad
 static void json_lib_error(struct json_ctx *ctx, json_error_t *err)
8ff5ad
 {
8ff5ad
 	struct location loc = {
8ff5ad
-		.indesc = &ctx->indesc,
8ff5ad
+		.indesc = &json_indesc,
8ff5ad
 		.line_offset = err->position - err->column,
8ff5ad
 		.first_line = err->line,
8ff5ad
 		.last_line = err->line,
8ff5ad
@@ -3864,16 +3864,15 @@ int nft_parse_json_buffer(struct nft_ctx *nft, const char *buf,
8ff5ad
 			  struct list_head *msgs, struct list_head *cmds)
8ff5ad
 {
8ff5ad
 	struct json_ctx ctx = {
8ff5ad
-		.indesc = {
8ff5ad
-			.type = INDESC_BUFFER,
8ff5ad
-			.data = buf,
8ff5ad
-		},
8ff5ad
 		.nft = nft,
8ff5ad
 		.msgs = msgs,
8ff5ad
 		.cmds = cmds,
8ff5ad
 	};
8ff5ad
 	int ret;
8ff5ad
 
8ff5ad
+	json_indesc.type = INDESC_BUFFER;
8ff5ad
+	json_indesc.data = buf;
8ff5ad
+
8ff5ad
 	parser_init(nft, nft->state, msgs, cmds, nft->top_scope);
8ff5ad
 	nft->json_root = json_loads(buf, 0, NULL);
8ff5ad
 	if (!nft->json_root)
8ff5ad
@@ -3892,10 +3891,6 @@ int nft_parse_json_filename(struct nft_ctx *nft, const char *filename,
8ff5ad
 			    struct list_head *msgs, struct list_head *cmds)
8ff5ad
 {
8ff5ad
 	struct json_ctx ctx = {
8ff5ad
-		.indesc = {
8ff5ad
-			.type = INDESC_FILE,
8ff5ad
-			.name = filename,
8ff5ad
-		},
8ff5ad
 		.nft = nft,
8ff5ad
 		.msgs = msgs,
8ff5ad
 		.cmds = cmds,
8ff5ad
@@ -3903,6 +3898,9 @@ int nft_parse_json_filename(struct nft_ctx *nft, const char *filename,
8ff5ad
 	json_error_t err;
8ff5ad
 	int ret;
8ff5ad
 
8ff5ad
+	json_indesc.type = INDESC_FILE;
8ff5ad
+	json_indesc.name = filename;
8ff5ad
+
8ff5ad
 	parser_init(nft, nft->state, msgs, cmds, nft->top_scope);
8ff5ad
 	nft->json_root = json_load_file(filename, 0, &err;;
8ff5ad
 	if (!nft->json_root)
8ff5ad
-- 
8ff5ad
2.31.1
8ff5ad