parser_json: reject non-concat expression
Florian Westphal
maintainerPATCH 1/1 parser_json: reject non-concat expression
Before "src: detach set, list and concatenation expression layout":
internal:0:0-0: Error: Concatenation with 0 elements is illegal
After this change, expr->size access triggers assert() failure, add explicit test for etype to avoid this and error out:
internal:0:0-0: Error: Expected concat element, got symbol.
Fixes e0d92243be1c ("src: detach set, list and concatenation expression layout")
Signed-off-by Florian Westphal <[email protected]>
--- src/parser_json.c | 7 ++++ .../nft-j-f/concat_is_not_concat_assert | 39 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/shell/testcases/bogons/nft-j-f/concat_is_not_concat_assert
src/parser_json.c +7 -0
@@ -1286,11 +1286,18 @@ static struct expr *json_parse_binop_expr(struct json_ctx *ctx,static struct expr *json_check_concat_expr (struct json_ctx *ctx,struct expr *e) { +if (e->etype !=EXPR_CONCAT ) { +json_error (ctx,"Expected concatenation, got %s" ,expr_name (e)); + goto err_free; + } +if (expr_concat (e)->size >=2 )return e;json_error (ctx,"Concatenation with %d elements is illegal" ,expr_concat (e)->size); + +err_free:expr_free (e);return NULL ; }
tests/shell/testcases/bogons/nft-j-f/concat_is_not_concat_assert new file +39 -0
@@ -0,0 +1,39 @@ +{ + "nftables": [ + { + "metainfo": { +"ver": "ION", + "rame": "RAME", + "json_schema_version": 1 + } + }, + { + "table": { "family": "ip", "name": "filter", + "le": 0 + } + }, + { + "set": { + "family": "ip", + "name": "test_set", + "table": "filter", + "type": [ + "iface_index", "ether_addr", "ipv4_addr" + ], + "he": 0, + "flags": "interval", +"elem": [ + { + "elem": { + "val": { + "concat": [ + "10.1.2.3" + ] }, + "comment": "90" +} + } + ] + } +} + ] +}
Signature · 1 line
2.49.1
Quoted 10 lines · Florian Westphal
Before "src: detach set, list and concatenation expression layout":
internal:0:0-0: Error: Concatenation with 0 elements is illegalAfter this change,
expr->sizeaccess triggersassert()failure, add explicit test for etype to avoid this and error out:internal:0:0-0: Error: Expected concat element, got symbol.
Fixes e0d92243be1c ("src: detach set, list and concatenation expression layout")Signed-off-by Florian Westphal <[email protected]>
Reviewed-by Pablo Neira Ayuso <[email protected]>