From 1fd8524ffd991d949ff77a9fd5e1b088cb942ed1 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Wed, 30 Aug 2023 13:08:17 +0200 Subject: src: use internal_location for unspecified location at allocation time Set location to internal_location instead of NULL to ensure this is always set. Signed-off-by: Pablo Neira Ayuso --- src/parser_bison.y | 8 ++++---- src/parser_json.c | 2 +- src/rule.c | 21 ++++++++++++++------- 3 files changed, 19 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/parser_bison.y b/src/parser_bison.y index 14aab193..a248b335 100644 --- a/src/parser_bison.y +++ b/src/parser_bison.y @@ -2134,7 +2134,7 @@ typeof_expr : primary_expr set_block_alloc : /* empty */ { - $$ = set_alloc(NULL); + $$ = set_alloc(&internal_location); } ; @@ -2214,7 +2214,7 @@ set_flag : CONSTANT { $$ = NFT_SET_CONSTANT; } map_block_alloc : /* empty */ { - $$ = set_alloc(NULL); + $$ = set_alloc(&internal_location); } ; @@ -2329,7 +2329,7 @@ set_policy_spec : PERFORMANCE { $$ = NFT_SET_POL_PERFORMANCE; } flowtable_block_alloc : /* empty */ { - $$ = flowtable_alloc(NULL); + $$ = flowtable_alloc(&internal_location); } ; @@ -2448,7 +2448,7 @@ data_type_expr : data_type_atom_expr obj_block_alloc : /* empty */ { - $$ = obj_alloc(NULL); + $$ = obj_alloc(&internal_location); } ; diff --git a/src/parser_json.c b/src/parser_json.c index 4ea5b432..01d42283 100644 --- a/src/parser_json.c +++ b/src/parser_json.c @@ -3175,7 +3175,7 @@ static struct cmd *json_parse_cmd_add_set(struct json_ctx *ctx, json_t *root, break; } - set = set_alloc(NULL); + set = set_alloc(&internal_location); if (json_unpack(root, "{s:o}", "type", &tmp)) { json_error(ctx, "Invalid set type."); diff --git a/src/rule.c b/src/rule.c index bbea05d5..07b95a99 100644 --- a/src/rule.c +++ b/src/rule.c @@ -148,11 +148,12 @@ struct set *set_alloc(const struct location *loc) { struct set *set; + assert(loc); + set = xzalloc(sizeof(*set)); set->refcnt = 1; set->handle.set_id = ++set_id; - if (loc != NULL) - set->location = *loc; + set->location = *loc; init_list_head(&set->stmt_list); @@ -163,7 +164,7 @@ struct set *set_clone(const struct set *set) { struct set *new_set; - new_set = set_alloc(NULL); + new_set = set_alloc(&internal_location); handle_merge(&new_set->handle, &set->handle); new_set->flags = set->flags; new_set->gc_int = set->gc_int; @@ -455,6 +456,8 @@ struct rule *rule_alloc(const struct location *loc, const struct handle *h) { struct rule *rule; + assert(loc); + rule = xzalloc(sizeof(*rule)); rule->location = *loc; init_list_head(&rule->list); @@ -1300,6 +1303,8 @@ struct cmd *cmd_alloc(enum cmd_ops op, enum cmd_obj obj, { struct cmd *cmd; + assert(loc); + cmd = xzalloc(sizeof(*cmd)); init_list_head(&cmd->list); cmd->op = op; @@ -1614,9 +1619,10 @@ struct obj *obj_alloc(const struct location *loc) { struct obj *obj; + assert(loc); + obj = xzalloc(sizeof(*obj)); - if (loc != NULL) - obj->location = *loc; + obj->location = *loc; obj->refcnt = 1; return obj; @@ -2025,9 +2031,10 @@ struct flowtable *flowtable_alloc(const struct location *loc) { struct flowtable *flowtable; + assert(loc); + flowtable = xzalloc(sizeof(*flowtable)); - if (loc != NULL) - flowtable->location = *loc; + flowtable->location = *loc; flowtable->refcnt = 1; return flowtable; -- cgit v1.2.3