From: Pablo Neira Ayuso <pablo@netfilter.org>
To: "Carlos Falgueras García" <carlosfg@riseup.net>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH 2/2 libnftnl] Check memory allocations in setters
Date: Fri, 10 Jun 2016 13:15:55 +0200 [thread overview]
Message-ID: <20160610111555.GA1194@salvia> (raw)
In-Reply-To: <1465554054-16283-2-git-send-email-carlosfg@riseup.net>
On Fri, Jun 10, 2016 at 12:20:54PM +0200, Carlos Falgueras García wrote:
> When you set an object attribute the memory is copied, sometimes an
> allocations is needed and it must be checked. Before this patch all setters
> method return void, so this patch makes all setters return int instead void
> to communicate the error to user.
>
> Summary:
> * All setters return int instead void
> * All memory allocations inside setters are checked
> * Unsetters are used if is possible in order to consolidate
>
> Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
> ---
> include/libnftnl/chain.h | 16 +++++++-------
> include/libnftnl/expr.h | 12 +++++------
> include/libnftnl/gen.h | 8 +++----
> include/libnftnl/rule.h | 12 +++++------
> include/libnftnl/ruleset.h | 2 +-
> include/libnftnl/set.h | 20 ++++++++---------
> include/libnftnl/table.h | 12 +++++------
> src/chain.c | 54 +++++++++++++++++++++++++---------------------
> src/expr.c | 36 ++++++++++++++++++-------------
> src/expr/dynset.c | 5 ++++-
> src/expr/immediate.c | 6 +++---
> src/expr/log.c | 7 ++++--
> src/expr/lookup.c | 5 ++++-
> src/gen.c | 20 ++++++++++-------
> src/rule.c | 46 ++++++++++++++++++++-------------------
> src/ruleset.c | 19 ++++++++++------
> src/set.c | 40 ++++++++++++++++++----------------
> src/set_elem.c | 33 ++++++++++++++--------------
> src/table.c | 28 +++++++++++++-----------
> 19 files changed, 210 insertions(+), 171 deletions(-)
>
> diff --git a/include/libnftnl/chain.h b/include/libnftnl/chain.h
> index 954b39f..6419dee 100644
> --- a/include/libnftnl/chain.h
> +++ b/include/libnftnl/chain.h
> @@ -36,14 +36,14 @@ enum nftnl_chain_attr {
>
> bool nftnl_chain_is_set(const struct nftnl_chain *c, uint16_t attr);
> void nftnl_chain_unset(struct nftnl_chain *c, uint16_t attr);
> -void nftnl_chain_set(struct nftnl_chain *t, uint16_t attr, const void *data);
> -void nftnl_chain_set_data(struct nftnl_chain *t, uint16_t attr,
> - const void *data, uint32_t data_len);
> -void nftnl_chain_set_u8(struct nftnl_chain *t, uint16_t attr, uint8_t data);
> -void nftnl_chain_set_u32(struct nftnl_chain *t, uint16_t attr, uint32_t data);
> -void nftnl_chain_set_s32(struct nftnl_chain *t, uint16_t attr, int32_t data);
> -void nftnl_chain_set_u64(struct nftnl_chain *t, uint16_t attr, uint64_t data);
> -void nftnl_chain_set_str(struct nftnl_chain *t, uint16_t attr, const char *str);
> +int nftnl_chain_set(struct nftnl_chain *t, uint16_t attr, const void *data);
> +int nftnl_chain_set_data(struct nftnl_chain *t, uint16_t attr,
> + const void *data, uint32_t data_len);
> +int nftnl_chain_set_u8(struct nftnl_chain *t, uint16_t attr, uint8_t data);
> +int nftnl_chain_set_u32(struct nftnl_chain *t, uint16_t attr, uint32_t data);
> +int nftnl_chain_set_s32(struct nftnl_chain *t, uint16_t attr, int32_t data);
> +int nftnl_chain_set_u64(struct nftnl_chain *t, uint16_t attr, uint64_t data);
_set_uXX never fail, so leave them using void as this just makes this
more complicated.
Please only update _set_data() and _set_str() as in my original patch
that I handed over to you. Thanks.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2016-06-10 11:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-10 10:20 [PATCH 1/2 libnftnl] Fix leak in nftnl_*_unset() Carlos Falgueras García
2016-06-10 10:20 ` [PATCH 2/2 libnftnl] Check memory allocations in setters Carlos Falgueras García
2016-06-10 11:15 ` Pablo Neira Ayuso [this message]
2016-06-10 11:14 ` [PATCH 1/2 libnftnl] Fix leak in nftnl_*_unset() Arturo Borrero Gonzalez
2016-06-10 11:21 ` Carlos Falgueras García
-- strict thread matches above, loose matches on Subject: below --
2016-06-02 10:40 [PATCH 1/2,libnftnl] Free user data in unsetters Carlos Falgueras García
2016-06-02 10:40 ` [PATCH 2/2,libnftnl] Check memory allocations in setters Carlos Falgueras García
2016-06-02 10:57 ` Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160610111555.GA1194@salvia \
--to=pablo@netfilter.org \
--cc=carlosfg@riseup.net \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).