From b674a8e78bf21985a05e17a3038f670bd8f46482 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Fri, 10 Jun 2016 14:47:53 +0200 Subject: src: check for strdup() errors from setters and parsers And pass up an error to the caller. Signed-off-by: Pablo Neira Ayuso --- src/set.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/set.c') diff --git a/src/set.c b/src/set.c index 02d0890..c23c378 100644 --- a/src/set.c +++ b/src/set.c @@ -294,10 +294,16 @@ struct nftnl_set *nftnl_set_clone(const struct nftnl_set *set) memcpy(newset, set, sizeof(*set)); - if (set->flags & (1 << NFTNL_SET_TABLE)) + if (set->flags & (1 << NFTNL_SET_TABLE)) { newset->table = strdup(set->table); - if (set->flags & (1 << NFTNL_SET_NAME)) + if (!newset->table) + goto err; + } + if (set->flags & (1 << NFTNL_SET_NAME)) { newset->name = strdup(set->name); + if (!newset->name) + goto err; + } INIT_LIST_HEAD(&newset->element_list); list_for_each_entry(elem, &set->element_list, head) { @@ -440,11 +446,15 @@ int nftnl_set_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_set *s) if (tb[NFTA_SET_TABLE]) { xfree(s->table); s->table = strdup(mnl_attr_get_str(tb[NFTA_SET_TABLE])); + if (!s->table) + return -1; s->flags |= (1 << NFTNL_SET_TABLE); } if (tb[NFTA_SET_NAME]) { xfree(s->name); s->name = strdup(mnl_attr_get_str(tb[NFTA_SET_NAME])); + if (!s->name) + return -1; s->flags |= (1 << NFTNL_SET_NAME); } if (tb[NFTA_SET_FLAGS]) { -- cgit v1.2.3