DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Andrew Rybchenko <arybchenko@solarflare.com>
Cc: <dev@dpdk.org>, Ferruh Yigit <ferruh.yigit@intel.com>,
	Thomas Monjalon <thomas@monjalon.net>
Subject: Re: [dpdk-dev] [PATCH 2/2] ethdev: use strlcpy instead of snprintf on initialization
Date: Fri, 1 Mar 2019 10:42:21 -0800	[thread overview]
Message-ID: <20190301104221.0d767d69@shemminger-XPS-13-9360> (raw)
In-Reply-To: <8f248bd3-1ae6-c8a1-ee6e-37742bd6ea90@solarflare.com>

On Fri, 1 Mar 2019 10:48:58 +0300
Andrew Rybchenko <arybchenko@solarflare.com> wrote:

> On 3/1/19 1:47 AM, Stephen Hemminger wrote:
> > Don't need to use snprintf for simple name copy.
> >
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > ---
> >   lib/librte_ethdev/rte_ethdev.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
> > index 95889ed206db..8bd54dcf58c1 100644
> > --- a/lib/librte_ethdev/rte_ethdev.c
> > +++ b/lib/librte_ethdev/rte_ethdev.c
> > @@ -459,7 +459,7 @@ rte_eth_dev_allocate(const char *name)
> >   	}
> >   
> >   	eth_dev = eth_dev_get(port_id);
> > -	snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
> > +	strlcpy(eth_dev->data->name, name, RTE_ETH_NAME_MAX_LEN);  
> 
> Why is sizeof() substituted with RTE_ETH_NAME_MAX_LEN?

Same thing, I just wanted to make the length obvious to the reader.

> I thought that sizeof() is the first choice in such cases since it is a 
> bit more
> safer vs possible changes in the code.
> 
> BTW, wouldn't it be more friendly to check name length on entry and
> reject if it is too long? (and same for rte_eth_dev_create())

It is impossible for name to long since since both structures are the same.

> I agree that strlcpy() should be used anyway.
> 
> >   	eth_dev->data->port_id = port_id;
> >   	eth_dev->data->mtu = ETHER_MTU;
> >     
> 

  reply	other threads:[~2019-03-01 18:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-28 22:47 [dpdk-dev] [PATCH 0/2] ethdev: use strlcpy Stephen Hemminger
2019-02-28 22:47 ` [dpdk-dev] [PATCH 1/2] ethdev: replace snprintf with strlcpy Stephen Hemminger
2019-03-01  7:40   ` Andrew Rybchenko
2019-02-28 22:47 ` [dpdk-dev] [PATCH 2/2] ethdev: use strlcpy instead of snprintf on initialization Stephen Hemminger
2019-03-01  6:54   ` Rami Rosen
2019-03-01  7:48   ` Andrew Rybchenko
2019-03-01 18:42     ` Stephen Hemminger [this message]
2019-03-04  9:11       ` Andrew Rybchenko
2019-03-04 19:12         ` Stephen Hemminger
2019-03-06 15:55           ` Ferruh Yigit
2019-03-13 18:17 ` [dpdk-dev] [PATCH 0/2] ethdev: use strlcpy Ferruh Yigit

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=20190301104221.0d767d69@shemminger-XPS-13-9360 \
    --to=stephen@networkplumber.org \
    --cc=arybchenko@solarflare.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=thomas@monjalon.net \
    /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).