summaryrefslogtreecommitdiffstats
path: root/src/parser_json.c
diff options
context:
space:
mode:
authorEric Garver <eric@garver.life>2019-05-01 12:25:37 -0400
committerPablo Neira Ayuso <pablo@netfilter.org>2019-05-03 18:14:19 +0200
commit2d908943fa5515f27ef5dde249d0b08b92aa7ff0 (patch)
treee3ef7434cdc43d50689f9ce81180c2fa3ca7198e /src/parser_json.c
parent55715486efba424e97361c81d8d47e854f45a5a6 (diff)
parser_json: fix off by one index on rule add/replace
We need to increment the index by one just as the CLI does. Fixes: 586ad210368b7 ("libnftables: Implement JSON parser") Signed-off-by: Eric Garver <eric@garver.life> Acked-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/parser_json.c')
-rw-r--r--src/parser_json.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/parser_json.c b/src/parser_json.c
index 72e712f3..c57c4b8a 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -2462,7 +2462,9 @@ static struct cmd *json_parse_cmd_add_rule(struct json_ctx *ctx, json_t *root,
return NULL;
}
- json_unpack(root, "{s:i}", "index", &h.index.id);
+ if (!json_unpack(root, "{s:I}", "index", &h.index.id)) {
+ h.index.id++;
+ }
rule = rule_alloc(int_loc, NULL);
@@ -3040,7 +3042,9 @@ static struct cmd *json_parse_cmd_replace(struct json_ctx *ctx,
"expr", &tmp))
return NULL;
json_unpack(root, "{s:I}", "handle", &h.handle.id);
- json_unpack(root, "{s:I}", "index", &h.index.id);
+ if (!json_unpack(root, "{s:I}", "index", &h.index.id)) {
+ h.index.id++;
+ }
if (op == CMD_REPLACE && !h.handle.id) {
json_error(ctx, "Handle is required when replacing a rule.");