diff mbox series

[nft] parser_json: fix off by one index on rule add/replace

Message ID 20190501162537.29318-1-eric@garver.life
State Accepted
Delegated to: Pablo Neira
Headers show
Series [nft] parser_json: fix off by one index on rule add/replace | expand

Commit Message

Eric Garver May 1, 2019, 4:25 p.m. UTC
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>
---
 src/parser_json.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Phil Sutter May 3, 2019, 3:42 p.m. UTC | #1
On Wed, May 01, 2019 at 12:25:37PM -0400, Eric Garver wrote:
> 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>
Pablo Neira Ayuso May 3, 2019, 4:15 p.m. UTC | #2
On Wed, May 01, 2019 at 12:25:37PM -0400, Eric Garver wrote:
> We need to increment the index by one just as the CLI does.

Applied, thanks.
diff mbox series

Patch

diff --git a/src/parser_json.c b/src/parser_json.c
index 5c00c9b003b6..10ce259f0241 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.");