* [dpdk-dev] [PATCH 0/2] ethdev: use strlcpy @ 2019-02-28 22:47 Stephen Hemminger 2019-02-28 22:47 ` [dpdk-dev] [PATCH 1/2] ethdev: replace snprintf with strlcpy Stephen Hemminger ` (2 more replies) 0 siblings, 3 replies; 11+ messages in thread From: Stephen Hemminger @ 2019-02-28 22:47 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger A couple of places in ethdev are clearer if strlcpy is used. Stephen Hemminger (2): ethdev: replace snprintf with strlcpy ethdev: use strlcpy instead of snprintf on initialization lib/librte_ethdev/rte_ethdev.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) -- 2.17.1 ^ permalink raw reply [flat|nested] 11+ messages in thread
* [dpdk-dev] [PATCH 1/2] ethdev: replace snprintf with strlcpy 2019-02-28 22:47 [dpdk-dev] [PATCH 0/2] ethdev: use strlcpy Stephen Hemminger @ 2019-02-28 22:47 ` 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-13 18:17 ` [dpdk-dev] [PATCH 0/2] ethdev: use strlcpy Ferruh Yigit 2 siblings, 1 reply; 11+ messages in thread From: Stephen Hemminger @ 2019-02-28 22:47 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger The set_port_owner was copying a string between structures of the same type, therefore the name could never be truncated (unless source string was not null terminated). Use strlcpy which does it better. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- lib/librte_ethdev/rte_ethdev.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 85c1794968dd..95889ed206db 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -585,7 +585,6 @@ _rte_eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id, { struct rte_eth_dev *ethdev = &rte_eth_devices[port_id]; struct rte_eth_dev_owner *port_owner; - int sret; if (port_id >= RTE_MAX_ETHPORTS || !is_allocated(ethdev)) { RTE_ETHDEV_LOG(ERR, "Port id %"PRIu16" is not allocated\n", @@ -609,11 +608,8 @@ _rte_eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id, return -EPERM; } - sret = snprintf(port_owner->name, RTE_ETH_MAX_OWNER_NAME_LEN, "%s", - new_owner->name); - if (sret < 0 || sret >= RTE_ETH_MAX_OWNER_NAME_LEN) - RTE_ETHDEV_LOG(ERR, "Port %u owner name was truncated\n", - port_id); + /* can not truncate (same structure) */ + strlcpy(port_owner->name, new_owner->name, RTE_ETH_MAX_OWNER_NAME_LEN); port_owner->id = new_owner->id; -- 2.17.1 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-dev] [PATCH 1/2] ethdev: replace snprintf with strlcpy 2019-02-28 22:47 ` [dpdk-dev] [PATCH 1/2] ethdev: replace snprintf with strlcpy Stephen Hemminger @ 2019-03-01 7:40 ` Andrew Rybchenko 0 siblings, 0 replies; 11+ messages in thread From: Andrew Rybchenko @ 2019-03-01 7:40 UTC (permalink / raw) To: Stephen Hemminger, dev On 3/1/19 1:47 AM, Stephen Hemminger wrote: > The set_port_owner was copying a string between structures of the > same type, therefore the name could never be truncated (unless source > string was not null terminated). Use strlcpy which does it better. > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Andrew Rybchenko <arybchenko@solarflare.com> ^ permalink raw reply [flat|nested] 11+ messages in thread
* [dpdk-dev] [PATCH 2/2] ethdev: use strlcpy instead of snprintf on initialization 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-02-28 22:47 ` Stephen Hemminger 2019-03-01 6:54 ` Rami Rosen 2019-03-01 7:48 ` Andrew Rybchenko 2019-03-13 18:17 ` [dpdk-dev] [PATCH 0/2] ethdev: use strlcpy Ferruh Yigit 2 siblings, 2 replies; 11+ messages in thread From: Stephen Hemminger @ 2019-02-28 22:47 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger 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); eth_dev->data->port_id = port_id; eth_dev->data->mtu = ETHER_MTU; -- 2.17.1 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-dev] [PATCH 2/2] ethdev: use strlcpy instead of snprintf on initialization 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 1 sibling, 0 replies; 11+ messages in thread From: Rami Rosen @ 2019-03-01 6:54 UTC (permalink / raw) To: Stephen Hemminger; +Cc: dev Reviewed-by: Rami Rosen <ramirose@gmail.com> ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-dev] [PATCH 2/2] ethdev: use strlcpy instead of snprintf on initialization 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 1 sibling, 1 reply; 11+ messages in thread From: Andrew Rybchenko @ 2019-03-01 7:48 UTC (permalink / raw) To: Stephen Hemminger, dev; +Cc: Ferruh Yigit, Thomas Monjalon 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? 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()) I agree that strlcpy() should be used anyway. > eth_dev->data->port_id = port_id; > eth_dev->data->mtu = ETHER_MTU; > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-dev] [PATCH 2/2] ethdev: use strlcpy instead of snprintf on initialization 2019-03-01 7:48 ` Andrew Rybchenko @ 2019-03-01 18:42 ` Stephen Hemminger 2019-03-04 9:11 ` Andrew Rybchenko 0 siblings, 1 reply; 11+ messages in thread From: Stephen Hemminger @ 2019-03-01 18:42 UTC (permalink / raw) To: Andrew Rybchenko; +Cc: dev, Ferruh Yigit, Thomas Monjalon 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; > > > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-dev] [PATCH 2/2] ethdev: use strlcpy instead of snprintf on initialization 2019-03-01 18:42 ` Stephen Hemminger @ 2019-03-04 9:11 ` Andrew Rybchenko 2019-03-04 19:12 ` Stephen Hemminger 0 siblings, 1 reply; 11+ messages in thread From: Andrew Rybchenko @ 2019-03-04 9:11 UTC (permalink / raw) To: Stephen Hemminger; +Cc: dev, Ferruh Yigit, Thomas Monjalon On 3/1/19 9:42 PM, Stephen Hemminger wrote: > 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. Which structures? name is an input parameter of the function. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-dev] [PATCH 2/2] ethdev: use strlcpy instead of snprintf on initialization 2019-03-04 9:11 ` Andrew Rybchenko @ 2019-03-04 19:12 ` Stephen Hemminger 2019-03-06 15:55 ` Ferruh Yigit 0 siblings, 1 reply; 11+ messages in thread From: Stephen Hemminger @ 2019-03-04 19:12 UTC (permalink / raw) To: Andrew Rybchenko; +Cc: dev, Ferruh Yigit, Thomas Monjalon On Mon, 4 Mar 2019 12:11:20 +0300 Andrew Rybchenko <arybchenko@solarflare.com> wrote: > On 3/1/19 9:42 PM, Stephen Hemminger wrote: > > 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. > > Which structures? name is an input parameter of the function. > Sorry my confusion, that was in patch 1. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-dev] [PATCH 2/2] ethdev: use strlcpy instead of snprintf on initialization 2019-03-04 19:12 ` Stephen Hemminger @ 2019-03-06 15:55 ` Ferruh Yigit 0 siblings, 0 replies; 11+ messages in thread From: Ferruh Yigit @ 2019-03-06 15:55 UTC (permalink / raw) To: Stephen Hemminger, Andrew Rybchenko; +Cc: dev, Thomas Monjalon On 3/4/2019 7:12 PM, Stephen Hemminger wrote: > On Mon, 4 Mar 2019 12:11:20 +0300 > Andrew Rybchenko <arybchenko@solarflare.com> wrote: > >> On 3/1/19 9:42 PM, Stephen Hemminger wrote: >>> 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. >> >> Which structures? name is an input parameter of the function. >> > > Sorry my confusion, that was in patch 1. Only concern is keep using "sizeof(eth_dev->data->name)" or RTE_ETH_NAME_MAX_LEN, both are correct but I agree with Andrew about using sizeof. Stephen, Would you be OK if I update it to sizeof() while merging, so I can merge them? Thanks, ferruh ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-dev] [PATCH 0/2] ethdev: use strlcpy 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-02-28 22:47 ` [dpdk-dev] [PATCH 2/2] ethdev: use strlcpy instead of snprintf on initialization Stephen Hemminger @ 2019-03-13 18:17 ` Ferruh Yigit 2 siblings, 0 replies; 11+ messages in thread From: Ferruh Yigit @ 2019-03-13 18:17 UTC (permalink / raw) To: Stephen Hemminger, dev; +Cc: Andrew Rybchenko, Rami Rosen On 2/28/2019 10:47 PM, Stephen Hemminger wrote: > A couple of places in ethdev are clearer if strlcpy is used. > > Stephen Hemminger (2): > ethdev: replace snprintf with strlcpy > ethdev: use strlcpy instead of snprintf on initialization Series applied to dpdk-next-net/master, thanks. (2/2 updated as suggested while merging.) ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2019-03-13 18:17 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 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
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).