netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] parser_json: fix parsing prefix inside concat
@ 2020-02-20 17:12 Eric Garver
  2020-02-20 17:12 ` [PATCH 2/2] tests: shell: json " Eric Garver
  2020-02-21 18:16 ` [PATCH 1/2] parser_json: fix " Eric Garver
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Garver @ 2020-02-20 17:12 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Pablo Neira Ayuso, Phil Sutter, Stefano Brivio

Found while testing set intervals + concatenations. Thanks to Stefano
Brivio for pointing me to the fix.

Signed-off-by: Eric Garver <eric@garver.life>
---
 src/parser_json.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/parser_json.c b/src/parser_json.c
index 85082ccee7ef..77abca032902 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -1058,7 +1058,7 @@ static struct expr *json_parse_concat_expr(struct json_ctx *ctx,
 	}
 
 	json_array_foreach(root, index, value) {
-		tmp = json_parse_primary_expr(ctx, value);
+		tmp = json_parse_rhs_expr(ctx, value);
 		if (!tmp) {
 			json_error(ctx, "Parsing expr at index %zd failed.", index);
 			expr_free(expr);
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] tests: shell: json parsing prefix inside concat
  2020-02-20 17:12 [PATCH 1/2] parser_json: fix parsing prefix inside concat Eric Garver
@ 2020-02-20 17:12 ` Eric Garver
  2020-02-21 18:16 ` [PATCH 1/2] parser_json: fix " Eric Garver
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Garver @ 2020-02-20 17:12 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Pablo Neira Ayuso, Phil Sutter, Stefano Brivio

Signed-off-by: Eric Garver <eric@garver.life>
---

# ./run-tests.sh ./testcases/sets/0044json_prefix_in_concat_0
I: using nft binary ./../../src/nft

I: [OK]         ./testcases/sets/0044json_prefix_in_concat_0

I: results: [OK] 1 [FAILED] 0 [TOTAL] 1


# NFT=/usr/sbin/nft ./run-tests.sh ./testcases/sets/0044json_prefix_in_concat_0
I: using nft binary /usr/sbin/nft

W: [FAILED]     ./testcases/sets/0044json_prefix_in_concat_0: got 
internal:0:0-0: Error: Expression type prefix not allowed in context (RHS, PRIMARY).

internal:0:0-0: Error: Parsing expr at index 0 failed.

internal:0:0-0: Error: Invalid set elem at index 0.

internal:0:0-0: Error: Invalid set.

internal:0:0-0: Error: Parsing command array at index 3 failed.

I: results: [OK] 0 [FAILED] 1 [TOTAL] 1

---
 .../shell/testcases/sets/0044json_prefix_in_concat_0  | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100755 tests/shell/testcases/sets/0044json_prefix_in_concat_0

diff --git a/tests/shell/testcases/sets/0044json_prefix_in_concat_0 b/tests/shell/testcases/sets/0044json_prefix_in_concat_0
new file mode 100755
index 000000000000..9bc48caa136f
--- /dev/null
+++ b/tests/shell/testcases/sets/0044json_prefix_in_concat_0
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# JSON parsing "prefix" inside "concat" for a set element
+
+RULESET='{"nftables": [{"metainfo": {"json_schema_version": 1}},
+         {"add": {"table": {"family": "inet", "name": "foobar_table"}}},
+         {"add": {"set": {"family": "inet", "name": "foobar_set", "table": "foobar_table", "type": ["ipv4_addr", "inet_proto", "inet_service"]}}},
+         {"add": {"element": {"elem": [{"concat": [{"prefix": {"addr": "10.10.10.0", "len": 24}}, "sctp", "1234"]}], "family": "inet", "name": "foobar_set", "table": "foobar_table"}}}]}'
+
+set -e
+$NFT -j -f - <<< "$RULESET"
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] parser_json: fix parsing prefix inside concat
  2020-02-20 17:12 [PATCH 1/2] parser_json: fix parsing prefix inside concat Eric Garver
  2020-02-20 17:12 ` [PATCH 2/2] tests: shell: json " Eric Garver
@ 2020-02-21 18:16 ` Eric Garver
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Garver @ 2020-02-21 18:16 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Pablo Neira Ayuso, Phil Sutter, Stefano Brivio

On Thu, Feb 20, 2020 at 12:12:41PM -0500, Eric Garver wrote:
> Found while testing set intervals + concatenations. Thanks to Stefano
> Brivio for pointing me to the fix.
> 
> Signed-off-by: Eric Garver <eric@garver.life>
> ---
>  src/parser_json.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/parser_json.c b/src/parser_json.c
> index 85082ccee7ef..77abca032902 100644
> --- a/src/parser_json.c
> +++ b/src/parser_json.c
> @@ -1058,7 +1058,7 @@ static struct expr *json_parse_concat_expr(struct json_ctx *ctx,
>  	}
>  
>  	json_array_foreach(root, index, value) {
> -		tmp = json_parse_primary_expr(ctx, value);
> +		tmp = json_parse_rhs_expr(ctx, value);
>  		if (!tmp) {
>  			json_error(ctx, "Parsing expr at index %zd failed.", index);
>  			expr_free(expr);
> -- 
> 2.23.0

Self NAK. This breaks "payload" inside of "concat".
Any help here would be appreciated. :)

Thanks.
Eric.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-21 18:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-20 17:12 [PATCH 1/2] parser_json: fix parsing prefix inside concat Eric Garver
2020-02-20 17:12 ` [PATCH 2/2] tests: shell: json " Eric Garver
2020-02-21 18:16 ` [PATCH 1/2] parser_json: fix " Eric Garver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).