From: Pablo Neira Ayuso <pablo@netfilter.org>
To: fgao@ikuai8.com
Cc: netfilter-devel@vger.kernel.org, gfree.wind@gmail.com
Subject: Re: [PATCH nf-next 1/1] netfilter: Use strlcpy to copy dev name instead of strncpy
Date: Thu, 5 Jan 2017 13:37:05 +0100 [thread overview]
Message-ID: <20170105123705.GA6658@salvia> (raw)
In-Reply-To: <1482837413-32048-1-git-send-email-fgao@ikuai8.com>
On Tue, Dec 27, 2016 at 07:16:53PM +0800, fgao@ikuai8.com wrote:
> From: Gao Feng <fgao@ikuai8.com>
>
> The current codes use strncpy to copy the dev name in
> nf_tables_newchain, there is no real issue now. Because the sizes of
> src and dst are IFNAMSIZ. But normally it should use count-1 with
> strncpy, because strncpy doesn't make sure the dst must be
> NULL-terminated when src exceeds the count bytes.
> So use strlcpy to replace the strncpy to make it clearer.
>
> Signed-off-by: Gao Feng <fgao@ikuai8.com>
> ---
> net/netfilter/nf_tables_api.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> index a019a87..dc50801 100644
> --- a/net/netfilter/nf_tables_api.c
> +++ b/net/netfilter/nf_tables_api.c
> @@ -1488,7 +1488,7 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,
> }
>
> if (hook.dev != NULL)
> - strncpy(basechain->dev_name, hook.dev->name, IFNAMSIZ);
> + strlcpy(basechain->dev_name, hook.dev->name, IFNAMSIZ);
I think this is not a problem, look:
[NFTA_HOOK_DEV] = { .type = NLA_STRING,
.len = IFNAMSIZ - 1 },
The netlink attribute policy enforces that NFTA_HOOK_DEV is always one
bytes smaller than the maximum length. So we guarantee that there's
room to nul-terminated this string.
> if (nla[NFTA_CHAIN_COUNTERS]) {
> stats = nft_stats_alloc(nla[NFTA_CHAIN_COUNTERS]);
> --
> 1.9.1
>
>
> --
> 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
prev parent reply other threads:[~2017-01-05 12:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-27 11:16 [PATCH nf-next 1/1] netfilter: Use strlcpy to copy dev name instead of strncpy fgao
2017-01-05 12:37 ` Pablo Neira Ayuso [this message]
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=20170105123705.GA6658@salvia \
--to=pablo@netfilter.org \
--cc=fgao@ikuai8.com \
--cc=gfree.wind@gmail.com \
--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).