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