nat_concat_map() requires a datamap, else we crash: set->data is dereferenced. Also update expr_evaluate_map() so that EXPR_SET_REF is checked there too. Signed-off-by: Florian Westphal <fw@xxxxxxxxx> --- src/evaluate.c | 9 +++++++++ .../bogons/nft-f/nat_stmt_with_set_instead_of_map | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/shell/testcases/bogons/nft-f/nat_stmt_with_set_instead_of_map diff --git a/src/evaluate.c b/src/evaluate.c index 1b3e8097454d..da382912ea71 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -2041,6 +2041,9 @@ static int expr_evaluate_map(struct eval_ctx *ctx, struct expr **expr) break; case EXPR_SET_REF: /* symbol has been already evaluated to set reference */ + if (!set_is_map(mappings->set->flags)) + return expr_error(ctx->msgs, map->mappings, + "Expression is not a map"); break; default: return expr_binary_error(ctx->msgs, map->mappings, map->map, @@ -3969,6 +3972,12 @@ static bool nat_concat_map(struct eval_ctx *ctx, struct stmt *stmt) if (expr_evaluate(ctx, &stmt->nat.addr->mappings)) return false; + if (!set_is_datamap(stmt->nat.addr->mappings->set->flags)) { + expr_error(ctx->msgs, stmt->nat.addr->mappings, + "Expression is not a map"); + return false; + } + if (stmt->nat.addr->mappings->set->data->etype == EXPR_CONCAT || stmt->nat.addr->mappings->set->data->dtype->subtypes) { stmt->nat.type_flags |= STMT_NAT_F_CONCAT; diff --git a/tests/shell/testcases/bogons/nft-f/nat_stmt_with_set_instead_of_map b/tests/shell/testcases/bogons/nft-f/nat_stmt_with_set_instead_of_map new file mode 100644 index 000000000000..b1302278cc9b --- /dev/null +++ b/tests/shell/testcases/bogons/nft-f/nat_stmt_with_set_instead_of_map @@ -0,0 +1,10 @@ +table inet x { + set y { + type ipv4_addr + elements = { 2.2.2.2, 3.3.3.3 } + } + + chain y { + snat ip to ip saddr map @y + } +} -- 2.41.0