summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2023-09-18 15:08:28 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2023-09-19 17:26:27 +0200
commit7b491e0c068c9881accfb571db3fb8f2f5799ca2 (patch)
treeb23ad7b86dff612ba716e2e5a7deaca5317e6a32 /src
parent56c90a2dd2eb9cb63a6d74d0f5ce8075bef3895b (diff)
evaluate: perform mark datatype compatibility check from maps
Wrap datatype compatibility check into a helper function and use it for map evaluation, otherwise the following bogus error message is displayed: Error: datatype mismatch, map expects packet mark, mapping expression has type integer Add unit tests to improve coverage for this usecase. Fixes: 5d8e33ddb112 ("evaluate: relax type-checking for integer arguments in mark statements") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r--src/evaluate.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/evaluate.c b/src/evaluate.c
index a537dcfd..03586922 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -1882,6 +1882,13 @@ static int mapping_expr_expand(struct eval_ctx *ctx)
return 0;
}
+static bool datatype_compatible(const struct datatype *a, const struct datatype *b)
+{
+ return (a->type == TYPE_MARK &&
+ datatype_equal(datatype_basetype(a), datatype_basetype(b))) ||
+ datatype_equal(a, b);
+}
+
static int expr_evaluate_map(struct eval_ctx *ctx, struct expr **expr)
{
struct expr *map = *expr, *mappings;
@@ -1989,7 +1996,7 @@ static int expr_evaluate_map(struct eval_ctx *ctx, struct expr **expr)
expr_name(map->mappings));
}
- if (!datatype_equal(map->map->dtype, map->mappings->set->key->dtype))
+ if (!datatype_compatible(map->mappings->set->key->dtype, map->map->dtype))
return expr_binary_error(ctx->msgs, map->mappings, map->map,
"datatype mismatch, map expects %s, "
"mapping expression has type %s",
@@ -2823,11 +2830,7 @@ static int __stmt_evaluate_arg(struct eval_ctx *ctx, struct stmt *stmt,
dtype->desc, (*expr)->dtype->desc,
(*expr)->len);
- if ((dtype->type == TYPE_MARK &&
- !datatype_equal(datatype_basetype(dtype), datatype_basetype((*expr)->dtype))) ||
- (dtype->type != TYPE_MARK &&
- (*expr)->dtype->type != TYPE_INTEGER &&
- !datatype_equal((*expr)->dtype, dtype)))
+ if (!datatype_compatible(dtype, (*expr)->dtype))
return stmt_binary_error(ctx, *expr, stmt, /* verdict vs invalid? */
"datatype mismatch: expected %s, "
"expression has type %s",
@@ -4385,7 +4388,7 @@ static int stmt_evaluate_objref_map(struct eval_ctx *ctx, struct stmt *stmt)
expr_name(map->mappings));
}
- if (!datatype_equal(map->map->dtype, map->mappings->set->key->dtype))
+ if (!datatype_compatible(map->mappings->set->key->dtype, map->map->dtype))
return expr_binary_error(ctx->msgs, map->mappings, map->map,
"datatype mismatch, map expects %s, "
"mapping expression has type %s",