diff mbox series

[v2] net/af_xdp: use strlcpy instead of strncpy

Message ID 20201007092050.27485-1-ciara.loftus@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers show
Series [v2] net/af_xdp: use strlcpy instead of strncpy | expand

Checks

Context Check Description
ci/iol-mellanox-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-testing success Testing PASS
ci/checkpatch warning coding style issues

Commit Message

Ciara Loftus Oct. 7, 2020, 9:20 a.m. UTC
strncpy may leave the destination buffer not NULL terminated so use
strlcpy instead.

Coverity issue: 362975
Fixes: 339b88c6a91f ("net/af_xdp: support multi-queue")
Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
---
v2:
* use strlcpy instead of snprintf

 drivers/net/af_xdp/rte_eth_af_xdp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Bruce Richardson Oct. 7, 2020, 10:29 a.m. UTC | #1
On Wed, Oct 07, 2020 at 09:20:50AM +0000, Ciara Loftus wrote:
> strncpy may leave the destination buffer not NULL terminated so use
> strlcpy instead.
> 
> Coverity issue: 362975
> Fixes: 339b88c6a91f ("net/af_xdp: support multi-queue")
> Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
> ---

Acked-by: Bruce Richardson <bruce.richardson@intel.com>

If the community prefers using rte_strscpy, this ack can also apply to v4
too. :-)

> v2:
> * use strlcpy instead of snprintf
> 
>  drivers/net/af_xdp/rte_eth_af_xdp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c
> index eaf2c9c873..ac00cbab8e 100644
> --- a/drivers/net/af_xdp/rte_eth_af_xdp.c
> +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
> @@ -1362,7 +1362,7 @@ xdp_get_channels_info(const char *if_name, int *max_queues,
>  
>  	channels.cmd = ETHTOOL_GCHANNELS;
>  	ifr.ifr_data = (void *)&channels;
> -	strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
> +	strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
>  	ret = ioctl(fd, SIOCETHTOOL, &ifr);
>  	if (ret) {
>  		if (errno == EOPNOTSUPP) {
> -- 
> 2.17.1
>
Ferruh Yigit Oct. 9, 2020, 4:31 p.m. UTC | #2
On 10/7/2020 11:29 AM, Bruce Richardson wrote:
> On Wed, Oct 07, 2020 at 09:20:50AM +0000, Ciara Loftus wrote:
>> strncpy may leave the destination buffer not NULL terminated so use
>> strlcpy instead.
>>
>> Coverity issue: 362975
>> Fixes: 339b88c6a91f ("net/af_xdp: support multi-queue")
>> Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
>> ---
> 
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> 

Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied to dpdk-next-net/main, thanks.
diff mbox series

Patch

diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c
index eaf2c9c873..ac00cbab8e 100644
--- a/drivers/net/af_xdp/rte_eth_af_xdp.c
+++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
@@ -1362,7 +1362,7 @@  xdp_get_channels_info(const char *if_name, int *max_queues,
 
 	channels.cmd = ETHTOOL_GCHANNELS;
 	ifr.ifr_data = (void *)&channels;
-	strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
+	strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
 	ret = ioctl(fd, SIOCETHTOOL, &ifr);
 	if (ret) {
 		if (errno == EOPNOTSUPP) {