]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
parser_json: fix off by one index on rule add/replace
authorEric Garver <eric@garver.life>
Wed, 1 May 2019 16:25:37 +0000 (12:25 -0400)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 3 May 2019 16:14:19 +0000 (18:14 +0200)
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>
src/parser_json.c

index 72e712f352e9feb0d3bc3bde86cd860acb9387ee..c57c4b8afc02e89175c65c6d2b6af5086fa44816 100644 (file)
@@ -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.");