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

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