From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft,v2 04/11] src: replace compound_expr_add() by type safe list_expr_add()
Date: Thu, 21 Aug 2025 11:23:23 +0200 [thread overview]
Message-ID: <20250821092330.2739989-5-pablo@netfilter.org> (raw)
In-Reply-To: <20250821092330.2739989-1-pablo@netfilter.org>
Replace compound_expr_add() by list_expr_add() to validate type.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/expression.h | 1 +
src/expression.c | 8 ++++++++
src/netlink_delinearize.c | 2 +-
src/parser_bison.y | 20 ++++++++++----------
src/parser_json.c | 6 +++---
src/trace.c | 10 +++++-----
6 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/include/expression.h b/include/expression.h
index 71a7298891cc..c2c59891a8a1 100644
--- a/include/expression.h
+++ b/include/expression.h
@@ -528,6 +528,7 @@ extern struct expr *concat_expr_alloc(const struct location *loc);
void concat_expr_add(struct expr *concat, struct expr *item);
extern struct expr *list_expr_alloc(const struct location *loc);
+void list_expr_add(struct expr *expr, struct expr *item);
struct expr *list_expr_to_binop(struct expr *expr);
extern struct expr *set_expr_alloc(const struct location *loc,
diff --git a/src/expression.c b/src/expression.c
index 106208f2b19c..22234567d2b1 100644
--- a/src/expression.c
+++ b/src/expression.c
@@ -1272,6 +1272,14 @@ struct expr *list_expr_alloc(const struct location *loc)
return compound_expr_alloc(loc, EXPR_LIST);
}
+void list_expr_add(struct expr *expr, struct expr *item)
+{
+ struct expr_list *expr_list = expr_list(expr);
+
+ list_add_tail(&item->list, &expr_list->expressions);
+ expr_list->size++;
+}
+
/* list is assumed to have two items at least, otherwise extend this! */
struct expr *list_expr_to_binop(struct expr *expr)
{
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index aa43ca85c5eb..c8644da960fa 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -2438,7 +2438,7 @@ static struct expr *binop_tree_to_list(struct expr *list, struct expr *expr)
} else {
if (list == NULL)
return expr_get(expr);
- compound_expr_add(list, expr_get(expr));
+ list_expr_add(list, expr_get(expr));
}
return list;
diff --git a/src/parser_bison.y b/src/parser_bison.y
index 401c17b0d3c6..6d4eb98f3b5a 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -2463,11 +2463,11 @@ flowtable_expr : '{' flowtable_list_expr '}'
flowtable_list_expr : flowtable_expr_member
{
$$ = compound_expr_alloc(&@$, EXPR_LIST);
- compound_expr_add($$, $1);
+ list_expr_add($$, $1);
}
| flowtable_list_expr COMMA flowtable_expr_member
{
- compound_expr_add($1, $3);
+ list_expr_add($1, $3);
$$ = $1;
}
| flowtable_list_expr COMMA opt_newline
@@ -2802,14 +2802,14 @@ dev_spec : DEVICE string
YYERROR;
$$ = compound_expr_alloc(&@$, EXPR_LIST);
- compound_expr_add($$, expr);
+ list_expr_add($$, expr);
}
| DEVICE variable_expr
{
datatype_set($2->sym->expr, &ifname_type);
$$ = compound_expr_alloc(&@$, EXPR_LIST);
- compound_expr_add($$, $2);
+ list_expr_add($$, $2);
}
| DEVICES '=' flowtable_expr
{
@@ -4977,13 +4977,13 @@ relational_expr : expr /* implicit */ rhs_expr
list_rhs_expr : basic_rhs_expr COMMA basic_rhs_expr
{
$$ = list_expr_alloc(&@$);
- compound_expr_add($$, $1);
- compound_expr_add($$, $3);
+ list_expr_add($$, $1);
+ list_expr_add($$, $3);
}
| list_rhs_expr COMMA basic_rhs_expr
{
$1->location = @$;
- compound_expr_add($1, $3);
+ list_expr_add($1, $3);
$$ = $1;
}
;
@@ -5531,13 +5531,13 @@ symbol_stmt_expr : symbol_expr
list_stmt_expr : symbol_stmt_expr COMMA symbol_stmt_expr
{
$$ = list_expr_alloc(&@$);
- compound_expr_add($$, $1);
- compound_expr_add($$, $3);
+ list_expr_add($$, $1);
+ list_expr_add($$, $3);
}
| list_stmt_expr COMMA symbol_stmt_expr
{
$1->location = @$;
- compound_expr_add($1, $3);
+ list_expr_add($1, $3);
$$ = $1;
}
;
diff --git a/src/parser_json.c b/src/parser_json.c
index 2216d41563b0..17e13ebe4458 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -1686,7 +1686,7 @@ static struct expr *json_parse_expr(struct json_ctx *ctx, json_t *root)
expr_free(list);
return NULL;
}
- compound_expr_add(list, expr);
+ list_expr_add(list, expr);
}
return list;
case JSON_TRUE:
@@ -3002,7 +3002,7 @@ static struct expr *json_parse_devs(struct json_ctx *ctx, json_t *root)
return NULL;
}
- compound_expr_add(expr, tmp);
+ list_expr_add(expr, tmp);
return expr;
}
if (!json_is_array(root)) {
@@ -3023,7 +3023,7 @@ static struct expr *json_parse_devs(struct json_ctx *ctx, json_t *root)
expr_free(expr);
return NULL;
}
- compound_expr_add(expr, tmp);
+ list_expr_add(expr, tmp);
}
return expr;
}
diff --git a/src/trace.c b/src/trace.c
index b270951025b8..b0f26e03169b 100644
--- a/src/trace.c
+++ b/src/trace.c
@@ -267,11 +267,11 @@ static struct expr *trace_alloc_list(const struct datatype *dtype,
if (bitv == 0)
continue;
- compound_expr_add(list_expr,
- constant_expr_alloc(&netlink_location,
- dtype, byteorder,
- len * BITS_PER_BYTE,
- &bitv));
+ list_expr_add(list_expr,
+ constant_expr_alloc(&netlink_location,
+ dtype, byteorder,
+ len * BITS_PER_BYTE,
+ &bitv));
}
mpz_clear(value);
--
2.30.2
next prev parent reply other threads:[~2025-08-21 9:23 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-21 9:23 [PATCH nft,v2 00/11] replace compound_expr_*() by type safe function Pablo Neira Ayuso
2025-08-21 9:23 ` [PATCH nft,v2 01/11] src: add expr_type_catchall() helper and use it Pablo Neira Ayuso
2025-08-21 9:23 ` [PATCH nft,v2 02/11] src: replace compound_expr_add() by type safe set_expr_add() Pablo Neira Ayuso
2025-08-21 9:23 ` [PATCH nft,v2 03/11] src: replace compound_expr_add() by type safe concat_expr_add() Pablo Neira Ayuso
2025-08-21 9:23 ` Pablo Neira Ayuso [this message]
2025-08-21 9:23 ` [PATCH nft,v2 05/11] segtree: rename set_compound_expr_add() to set_expr_add_splice() Pablo Neira Ayuso
2025-08-21 9:23 ` [PATCH nft,v2 06/11] expression: replace compound_expr_clone() by type safe function Pablo Neira Ayuso
2025-08-21 9:23 ` [PATCH nft,v2 07/11] expression: remove compound_expr_add() Pablo Neira Ayuso
2025-08-21 9:23 ` [PATCH nft,v2 08/11] expression: replace compound_expr_remove() by type safe function Pablo Neira Ayuso
2025-08-21 9:23 ` [PATCH nft,v2 09/11] expression: replace compound_expr_destroy() by type safe funtion Pablo Neira Ayuso
2025-08-21 9:23 ` [PATCH nft,v2 10/11] expression: replace compound_expr_print() by type safe function Pablo Neira Ayuso
2025-08-21 9:23 ` [PATCH nft,v2 11/11] src: replace compound_expr_alloc() " Pablo Neira Ayuso
2025-08-27 22:24 ` [PATCH nft,v2 00/11] replace compound_expr_*() " Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250821092330.2739989-5-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).