diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2016-06-10 16:45:48 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2016-06-15 13:26:33 +0200 |
commit | 50b175dbd598e80a0e67606645d1fa3c9be6ce01 (patch) | |
tree | bffe4211de5e4438a7c23514baa852bfa38e6fa0 /src/chain.c | |
parent | 46b887ca6b0382d135599a83ed0884aeaf97a357 (diff) |
src: check for flags before releasing attributes
Now that unsetters don't set pointers to NULL, check if the attribute is
set before trying to release it.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/chain.c')
-rw-r--r-- | src/chain.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/chain.c b/src/chain.c index 516b553..8cb3cf8 100644 --- a/src/chain.c +++ b/src/chain.c @@ -95,11 +95,11 @@ EXPORT_SYMBOL_ALIAS(nftnl_chain_alloc, nft_chain_alloc); void nftnl_chain_free(const struct nftnl_chain *c) { - if (c->table != NULL) + if (c->flags & (1 << NFTNL_CHAIN_TABLE)) xfree(c->table); - if (c->type != NULL) + if (c->flags & (1 << NFTNL_CHAIN_TYPE)) xfree(c->type); - if (c->dev != NULL) + if (c->flags & (1 << NFTNL_CHAIN_DEV)) xfree(c->dev); xfree(c); @@ -167,7 +167,7 @@ int nftnl_chain_set_data(struct nftnl_chain *c, uint16_t attr, strncpy(c->name, data, NFT_CHAIN_MAXNAMELEN); break; case NFTNL_CHAIN_TABLE: - if (c->table) + if (c->flags & (1 << NFTNL_CHAIN_TABLE)) xfree(c->table); c->table = strdup(data); @@ -199,7 +199,7 @@ int nftnl_chain_set_data(struct nftnl_chain *c, uint16_t attr, c->family = *((uint32_t *)data); break; case NFTNL_CHAIN_TYPE: - if (c->type) + if (c->flags & (1 << NFTNL_CHAIN_TYPE)) xfree(c->type); c->type = strdup(data); @@ -207,7 +207,7 @@ int nftnl_chain_set_data(struct nftnl_chain *c, uint16_t attr, return -1; break; case NFTNL_CHAIN_DEV: - if (c->dev) + if (c->flags & (1 << NFTNL_CHAIN_DEV)) xfree(c->dev); c->dev = strdup(data); @@ -533,7 +533,8 @@ int nftnl_chain_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_chain *c) c->flags |= (1 << NFTNL_CHAIN_NAME); } if (tb[NFTA_CHAIN_TABLE]) { - xfree(c->table); + if (c->flags & (1 << NFTNL_CHAIN_TABLE)) + xfree(c->table); c->table = strdup(mnl_attr_get_str(tb[NFTA_CHAIN_TABLE])); if (!c->table) return -1; @@ -562,7 +563,8 @@ int nftnl_chain_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_chain *c) c->flags |= (1 << NFTNL_CHAIN_HANDLE); } if (tb[NFTA_CHAIN_TYPE]) { - xfree(c->type); + if (c->flags & (1 << NFTNL_CHAIN_TYPE)) + xfree(c->type); c->type = strdup(mnl_attr_get_str(tb[NFTA_CHAIN_TYPE])); if (!c->type) return -1; |