Skip to contentSkip to conversation

parser_json: fix device parsing in netdev family

PATCH Superseded Pablo Neira Ayuso 1 participant 1 message Aug 2, 2022 netfilter

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH v2 1/1 parser_json: fix device parsing in netdev family

json_unpack() function is not designed to take a pre-allocated buffer.

Fixes 3fdc7541fba0 ("src: add multidevice support for netdev chain")

---
v2: skip initialization and add test.

 src/parser_json.c                 |  3 +--
 tests/shell/testcases/json/netdev | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)
 create mode 100755 tests/shell/testcases/json/netdev
src/parser_json.c +1 -2
index fb401009a499..9e93927a9a2b 100644
@@ -2780,8 +2780,7 @@ static struct cmd *json_parse_cmd_add_chain(struct json_ctx *ctx, json_t *root,
 	struct handle h = {
 		.table.location = *int_loc,
 	};
-	const char *family = "", *policy = "", *type, *hookstr;
-	const char name[IFNAMSIZ];
+	const char *family = "", *policy = "", *type, *hookstr, *name;
 	struct chain *chain;
 	int prio;
 
tests/shell/testcases/json/netdev new file +17 -0
new file mode 100755
index 000000000000..2cbc7e1f266c
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+ip link add d0 type dummy || {
+        echo "Skipping, no dummy interface available"
+        exit 0
+}
+trap "ip link del d0" EXIT
+
+$NFT flush ruleset
+$NFT add table inet test
+$NFT add chain inet test c
+
+$NFT flush ruleset
+
+RULESET='{"nftables":[{"flush":{"ruleset":null}},{"add":{"table":{"family":"netdev","name":"test_table"}}},{"add":{"chain":{"family":"netdev","table":"test_table","name":"test_chain","type":"filter","hook":"ingress","prio":0,"dev":"d0","policy":"accept"}}}]}'
+
+$NFT -j -f - <<< $RULESET
Signature · 1 line
2.30.2