[dpdk-dev,v4,11/18] net/sfc: correct strncpy length

Message ID 152600317109.53146.6555330710274289069.stgit@localhost.localdomain (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Andy Green May 11, 2018, 1:46 a.m. UTC
  Signed-off-by: Andy Green <andy@warmcat.com>
---
 drivers/net/sfc/sfc_ethdev.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Andrew Rybchenko May 11, 2018, 8:11 a.m. UTC | #1
On 05/11/2018 04:46 AM, Andy Green wrote:
> Signed-off-by: Andy Green <andy@warmcat.com>
> ---
>   drivers/net/sfc/sfc_ethdev.c |    4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c
> index e42d55350..ef5e9ecb2 100644
> --- a/drivers/net/sfc/sfc_ethdev.c
> +++ b/drivers/net/sfc/sfc_ethdev.c
> @@ -13,6 +13,7 @@
>   #include <rte_pci.h>
>   #include <rte_bus_pci.h>
>   #include <rte_errno.h>
> +#include <rte_string_fns.h>
>   
>   #include "efx.h"
>   
> @@ -741,9 +742,8 @@ sfc_xstats_get_names_by_id(struct rte_eth_dev *dev,
>   		if ((ids == NULL) || (ids[nb_written] == nb_supported)) {
>   			char *name = xstats_names[nb_written++].name;
>   
> -			strncpy(name, efx_mac_stat_name(sa->nic, i),
> +			strlcpy(name, efx_mac_stat_name(sa->nic, i),
>   				sizeof(xstats_names[0].name));
> -			name[sizeof(xstats_names[0].name) - 1] = '\0';
>   		}
>   
>   		++nb_supported;
>

Acked-by: Andrew Rybchenko <arybchenko@oktetlabs.ru>
  
De Lara Guarch, Pablo May 11, 2018, 10:51 a.m. UTC | #2
> -----Original Message-----

> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Andy Green

> Sent: Friday, May 11, 2018 2:46 AM

> To: dev@dpdk.org

> Subject: [dpdk-dev] [PATCH v4 11/18] net/sfc: correct strncpy length

> 

> Signed-off-by: Andy Green <andy@warmcat.com>

> ---

>  drivers/net/sfc/sfc_ethdev.c |    4 ++--

>  1 file changed, 2 insertions(+), 2 deletions(-)

> 

> diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index

> e42d55350..ef5e9ecb2 100644

> --- a/drivers/net/sfc/sfc_ethdev.c

> +++ b/drivers/net/sfc/sfc_ethdev.c

> @@ -13,6 +13,7 @@

>  #include <rte_pci.h>

>  #include <rte_bus_pci.h>

>  #include <rte_errno.h>

> +#include <rte_string_fns.h>

> 

>  #include "efx.h"

> 

> @@ -741,9 +742,8 @@ sfc_xstats_get_names_by_id(struct rte_eth_dev *dev,

>  		if ((ids == NULL) || (ids[nb_written] == nb_supported)) {

>  			char *name = xstats_names[nb_written++].name;

> 

> -			strncpy(name, efx_mac_stat_name(sa->nic, i),

> +			strlcpy(name, efx_mac_stat_name(sa->nic, i),

>  				sizeof(xstats_names[0].name));


Shouldn't this be "sizeof(name)"? Although probably it is the same.

Missing fixes line and CC stable.

Fixes: 73280c1e4ff2 ("net/sfc: support xstats retrieval by ID")
Cc: stable@dpdk.org
  
Andy Green May 12, 2018, 1:21 a.m. UTC | #3
On 05/11/2018 06:51 PM, De Lara Guarch, Pablo wrote:
> 
> 
>> -----Original Message-----
>> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Andy Green
>> Sent: Friday, May 11, 2018 2:46 AM
>> To: dev@dpdk.org
>> Subject: [dpdk-dev] [PATCH v4 11/18] net/sfc: correct strncpy length
>>
>> Signed-off-by: Andy Green <andy@warmcat.com>
>> ---
>>   drivers/net/sfc/sfc_ethdev.c |    4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index
>> e42d55350..ef5e9ecb2 100644
>> --- a/drivers/net/sfc/sfc_ethdev.c
>> +++ b/drivers/net/sfc/sfc_ethdev.c
>> @@ -13,6 +13,7 @@
>>   #include <rte_pci.h>
>>   #include <rte_bus_pci.h>
>>   #include <rte_errno.h>
>> +#include <rte_string_fns.h>
>>
>>   #include "efx.h"
>>
>> @@ -741,9 +742,8 @@ sfc_xstats_get_names_by_id(struct rte_eth_dev *dev,
>>   		if ((ids == NULL) || (ids[nb_written] == nb_supported)) {
>>   			char *name = xstats_names[nb_written++].name;
>>
>> -			strncpy(name, efx_mac_stat_name(sa->nic, i),
>> +			strlcpy(name, efx_mac_stat_name(sa->nic, i),
>>   				sizeof(xstats_names[0].name));
> 
> Shouldn't this be "sizeof(name)"? Although probably it is the same.

name is just a pointer, so sizeof that is 4 or 8.

-Andy

> Missing fixes line and CC stable.
> 
> Fixes: 73280c1e4ff2 ("net/sfc: support xstats retrieval by ID")
> Cc: stable@dpdk.org
>
  

Patch

diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c
index e42d55350..ef5e9ecb2 100644
--- a/drivers/net/sfc/sfc_ethdev.c
+++ b/drivers/net/sfc/sfc_ethdev.c
@@ -13,6 +13,7 @@ 
 #include <rte_pci.h>
 #include <rte_bus_pci.h>
 #include <rte_errno.h>
+#include <rte_string_fns.h>
 
 #include "efx.h"
 
@@ -741,9 +742,8 @@  sfc_xstats_get_names_by_id(struct rte_eth_dev *dev,
 		if ((ids == NULL) || (ids[nb_written] == nb_supported)) {
 			char *name = xstats_names[nb_written++].name;
 
-			strncpy(name, efx_mac_stat_name(sa->nic, i),
+			strlcpy(name, efx_mac_stat_name(sa->nic, i),
 				sizeof(xstats_names[0].name));
-			name[sizeof(xstats_names[0].name) - 1] = '\0';
 		}
 
 		++nb_supported;