summaryrefslogtreecommitdiffstats
path: root/src/parser_json.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2025-07-09 00:51:24 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2025-07-10 00:13:04 +0200
commite0d92243be1cf1a485450a56d845e7bf2d1c6051 (patch)
treef4617c607751577a635ed4c9ce4a386c19bd8add /src/parser_json.c
parent01fdd7c7f445337c460738aa872cbdaabb5316ea (diff)
src: detach set, list and concatenation expression layout
These three expressions use the same layout, but they have a different purpose. Several fields are specific of a given expression: - set_flags is only required by set expressions. - field_len and field_count are only used by concatenation expressions. Add accessors to validate the expression type before accessing the union fields: #define expr_set(__expr) (assert((__expr)->etype == EXPR_SET), &(__expr)->expr_set) #define expr_concat(__expr) (assert((__expr)->etype == EXPR_CONCAT), &(__expr)->expr_concat) #define expr_list(__expr) (assert((__expr)->etype == EXPR_LIST), &(__expr)->expr_list) This should help catch subtle bugs due to type confusion. assert() could be later enabled only in debugging builds to run tests, keep it by now. compound_expr_*() still works and it needs the same initial layout for all of these expressions: struct list_head expressions; unsigned int size; This is implicitly reducing the size of one of the largest structs in the union area of struct expr, still EXPR_SET_ELEM remains the largest so no gain is achieved in this iteration. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/parser_json.c')
-rw-r--r--src/parser_json.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/parser_json.c b/src/parser_json.c
index 08657f28..bd865de5 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -1286,10 +1286,11 @@ 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->size >= 2)
+ if (expr_concat(e)->size >= 2)
return e;
- json_error(ctx, "Concatenation with %d elements is illegal", e->size);
+ json_error(ctx, "Concatenation with %d elements is illegal",
+ expr_concat(e)->size);
expr_free(e);
return NULL;
}