]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: replace compound_expr_add() by type safe list_expr_add()
authorPablo Neira Ayuso <pablo@netfilter.org>
Wed, 13 Aug 2025 13:15:08 +0000 (15:15 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 27 Aug 2025 21:52:08 +0000 (23:52 +0200)
Replace compound_expr_add() by list_expr_add() to validate type.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/expression.h
src/expression.c
src/netlink_delinearize.c
src/parser_bison.y
src/parser_json.c
src/trace.c

index 0d9e10d7717e4c1934cf096e1170fa2a054444ca..ad469db2e136318b1959d693dd234c65083aafd1 100644 (file)
@@ -534,6 +534,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,
index 95cdedaa3bd685f2405b1d558f04d4c4904ed8f9..9521e67cca01a8aac882fc0ee2f81084a2e58385 100644 (file)
@@ -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)
 {
index ccccb67aa8fa541cc172d71babea0b796e49a898..990edc824ad9e0904c835e41c51adde41240af13 100644 (file)
@@ -2454,7 +2454,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;
index fd916f43404b33840a89bd34c929d75099261d51..bdcce4c1fbc9dfd012fd0b3f552a08d91401c175 100644 (file)
@@ -2503,11 +2503,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
@@ -2842,14 +2842,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
                        {
@@ -5199,13 +5199,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;
                        }
                        ;
@@ -5763,13 +5763,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;
                        }
                        ;
index 6ed1841c4e9c4579baf1a7b66d50abf7485c8d63..c107dfc88b0939ac4f8d6e5d59b7e3ae1c99ddb0 100644 (file)
@@ -1704,7 +1704,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:
@@ -3038,7 +3038,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)) {
@@ -3059,7 +3059,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;
 }
index 47f4c2159421e49708a504160f58bc3fc446521f..051cc12d7accc5716a7df782187450750abbb11a 100644 (file)
@@ -268,11 +268,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);