diff options
| author | Phil Sutter <phil@nwl.cc> | 2024-10-02 16:44:49 +0200 |
|---|---|---|
| committer | Phil Sutter <phil@nwl.cc> | 2025-10-18 21:11:27 +0200 |
| commit | 5a54b99859fd52d8c7e866b57f6d8fac3e20a78f (patch) | |
| tree | 6f4638c243b241886fdd0bb8916f074bcd0d12ad /src/expr/objref.c | |
| parent | 6f24a13a19b8690444564f50e1866fae5abf7687 (diff) | |
utils: Introduce nftnl_parse_str_attr()
Wrap the common parsing of string attributes in a function. Apart from
slightly reducing code size, this unifies callers in conditional freeing
of the field in case it was set before (missing in twelve spots) and
error checking for failing strdup()-calls (missing in four spots).
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'src/expr/objref.c')
| -rw-r--r-- | src/expr/objref.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/expr/objref.c b/src/expr/objref.c index 5fe09c2..1b27e94 100644 --- a/src/expr/objref.c +++ b/src/expr/objref.c @@ -144,21 +144,19 @@ static int nftnl_expr_objref_parse(struct nftnl_expr *e, struct nlattr *attr) ntohl(mnl_attr_get_u32(tb[NFTA_OBJREF_IMM_TYPE])); e->flags |= (1 << NFTNL_EXPR_OBJREF_IMM_TYPE); } - if (tb[NFTA_OBJREF_IMM_NAME]) { - objref->imm.name = - strdup(mnl_attr_get_str(tb[NFTA_OBJREF_IMM_NAME])); - e->flags |= (1 << NFTNL_EXPR_OBJREF_IMM_NAME); - } + if (nftnl_parse_str_attr(tb[NFTA_OBJREF_IMM_NAME], + NFTNL_EXPR_OBJREF_IMM_NAME, + &objref->imm.name, &e->flags) < 0) + return -1; if (tb[NFTA_OBJREF_SET_SREG]) { objref->set.sreg = ntohl(mnl_attr_get_u32(tb[NFTA_OBJREF_SET_SREG])); e->flags |= (1 << NFTNL_EXPR_OBJREF_SET_SREG); } - if (tb[NFTA_OBJREF_SET_NAME]) { - objref->set.name = - strdup(mnl_attr_get_str(tb[NFTA_OBJREF_SET_NAME])); - e->flags |= (1 << NFTNL_EXPR_OBJREF_SET_NAME); - } + if (nftnl_parse_str_attr(tb[NFTA_OBJREF_SET_NAME], + NFTNL_EXPR_OBJREF_SET_NAME, + &objref->set.name, &e->flags) < 0) + return -1; if (tb[NFTA_OBJREF_SET_ID]) { objref->set.id = ntohl(mnl_attr_get_u32(tb[NFTA_OBJREF_SET_ID])); |
