* [PATCH] net/smc: replace strncpy with strscpy
@ 2025-06-17 12:25 Pranav Tyagi
2025-06-18 10:50 ` Simon Horman
0 siblings, 1 reply; 3+ messages in thread
From: Pranav Tyagi @ 2025-06-17 12:25 UTC (permalink / raw)
To: wenjia, jaka, davem, edumazet, kuba, pabeni, linux-rdma,
linux-s390, netdev, linux-kernel
Cc: alibuda, tonylu, guwen, horms, skhan, linux-kernel-mentees,
Pranav Tyagi
Replace the deprecated strncpy() with strscpy() as the destination
buffer should be NUL-terminated and does not require any trailing
NUL-padding.
Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
---
net/smc/smc_pnet.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c
index b391c2ef463f..b70e1f3179c5 100644
--- a/net/smc/smc_pnet.c
+++ b/net/smc/smc_pnet.c
@@ -370,7 +370,7 @@ static int smc_pnet_add_eth(struct smc_pnettable *pnettable, struct net *net,
goto out_put;
new_pe->type = SMC_PNET_ETH;
memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
- strncpy(new_pe->eth_name, eth_name, IFNAMSIZ);
+ strscpy(new_pe->eth_name, eth_name, IFNAMSIZ);
rc = -EEXIST;
new_netdev = true;
mutex_lock(&pnettable->lock);
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net/smc: replace strncpy with strscpy
2025-06-17 12:25 [PATCH] net/smc: replace strncpy with strscpy Pranav Tyagi
@ 2025-06-18 10:50 ` Simon Horman
2025-06-18 14:32 ` Pranav Tyagi
0 siblings, 1 reply; 3+ messages in thread
From: Simon Horman @ 2025-06-18 10:50 UTC (permalink / raw)
To: Pranav Tyagi
Cc: wenjia, jaka, davem, edumazet, kuba, pabeni, linux-rdma,
linux-s390, netdev, linux-kernel, alibuda, tonylu, guwen, skhan,
linux-kernel-mentees
On Tue, Jun 17, 2025 at 05:55:12PM +0530, Pranav Tyagi wrote:
> Replace the deprecated strncpy() with strscpy() as the destination
> buffer should be NUL-terminated and does not require any trailing
> NUL-padding.
>
> Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
> ---
> net/smc/smc_pnet.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c
> index b391c2ef463f..b70e1f3179c5 100644
> --- a/net/smc/smc_pnet.c
> +++ b/net/smc/smc_pnet.c
> @@ -370,7 +370,7 @@ static int smc_pnet_add_eth(struct smc_pnettable *pnettable, struct net *net,
> goto out_put;
> new_pe->type = SMC_PNET_ETH;
> memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
> - strncpy(new_pe->eth_name, eth_name, IFNAMSIZ);
> + strscpy(new_pe->eth_name, eth_name, IFNAMSIZ);
Hi Pranav,
I think that because strscpy always results in a NULL terminated string
the length argument can be increased by one to IFNAMSIZ + 1, matching
the size of the destination.
But I also think that we can handle this automatically by switching
to the two-argument version of strscpy() because the destination is an
array.
strscpy(new_pe->eth_name, eth_name);
> rc = -EEXIST;
> new_netdev = true;
> mutex_lock(&pnettable->lock);
> --
> 2.49.0
>
--
pw-bot: changes-requested
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net/smc: replace strncpy with strscpy
2025-06-18 10:50 ` Simon Horman
@ 2025-06-18 14:32 ` Pranav Tyagi
0 siblings, 0 replies; 3+ messages in thread
From: Pranav Tyagi @ 2025-06-18 14:32 UTC (permalink / raw)
To: Simon Horman
Cc: wenjia, jaka, davem, edumazet, kuba, pabeni, linux-rdma,
linux-s390, netdev, linux-kernel, alibuda, tonylu, guwen, skhan,
linux-kernel-mentees
On Wed, Jun 18, 2025 at 4:20 PM Simon Horman <horms@kernel.org> wrote:
>
> On Tue, Jun 17, 2025 at 05:55:12PM +0530, Pranav Tyagi wrote:
> > Replace the deprecated strncpy() with strscpy() as the destination
> > buffer should be NUL-terminated and does not require any trailing
> > NUL-padding.
> >
> > Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
> > ---
> > net/smc/smc_pnet.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c
> > index b391c2ef463f..b70e1f3179c5 100644
> > --- a/net/smc/smc_pnet.c
> > +++ b/net/smc/smc_pnet.c
> > @@ -370,7 +370,7 @@ static int smc_pnet_add_eth(struct smc_pnettable *pnettable, struct net *net,
> > goto out_put;
> > new_pe->type = SMC_PNET_ETH;
> > memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
> > - strncpy(new_pe->eth_name, eth_name, IFNAMSIZ);
> > + strscpy(new_pe->eth_name, eth_name, IFNAMSIZ);
>
> Hi Pranav,
>
> I think that because strscpy always results in a NULL terminated string
> the length argument can be increased by one to IFNAMSIZ + 1, matching
> the size of the destination.
>
> But I also think that we can handle this automatically by switching
> to the two-argument version of strscpy() because the destination is an
> array.
>
> strscpy(new_pe->eth_name, eth_name);
>
> > rc = -EEXIST;
> > new_netdev = true;
> > mutex_lock(&pnettable->lock);
> > --
> > 2.49.0
> >
>
> --
> pw-bot: changes-requested
Hi,
Thanks for the feedback. Apologies for the oversight.
The size parameter should match the size of the destination.
Anyway, I will now use the two-argument version
send a v2.
Regards
Pranav Tyagi
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-18 14:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-17 12:25 [PATCH] net/smc: replace strncpy with strscpy Pranav Tyagi
2025-06-18 10:50 ` Simon Horman
2025-06-18 14:32 ` Pranav Tyagi
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).