linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] net/smc: Replace use of strncpy on NUL-terminated string with strscpy
@ 2025-09-01  3:04 James Flowers
  2025-09-01 16:03 ` Simon Horman
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: James Flowers @ 2025-09-01  3:04 UTC (permalink / raw)
  To: alibuda, dust.li, sidraya, wenjia, mjambigi, tonylu, guwen, davem,
	edumazet, kuba, pabeni, horms, skhan
  Cc: James Flowers, linux-rdma, linux-s390, netdev, linux-kernel,
	linux-kernel-mentees

strncpy is deprecated for use on NUL-terminated strings, as indicated in
Documentation/process/deprecated.rst. strncpy NUL-pads the destination
buffer and doesn't guarantee the destination buffer will be NUL
terminated.

Signed-off-by: James Flowers <bold.zone2373@fastmail.com>
---
V1 -> V2: Replaced with two argument version of strscpy
Note: this has only been compile tested.

 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 76ad29e31d60..b90337f86e83 100644
--- a/net/smc/smc_pnet.c
+++ b/net/smc/smc_pnet.c
@@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
 		return -ENOMEM;
 	new_pe->type = SMC_PNET_IB;
 	memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
-	strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX);
+	strscpy(new_pe->ib_name, ib_name);
 	new_pe->ib_port = ib_port;
 
 	new_ibdev = true;
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] net/smc: Replace use of strncpy on NUL-terminated string with strscpy
  2025-09-01  3:04 [PATCH v2] net/smc: Replace use of strncpy on NUL-terminated string with strscpy James Flowers
@ 2025-09-01 16:03 ` Simon Horman
  2025-09-02  4:09 ` Dust Li
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2025-09-01 16:03 UTC (permalink / raw)
  To: James Flowers
  Cc: alibuda, dust.li, sidraya, wenjia, mjambigi, tonylu, guwen, davem,
	edumazet, kuba, pabeni, skhan, linux-rdma, linux-s390, netdev,
	linux-kernel, linux-kernel-mentees

On Sun, Aug 31, 2025 at 08:04:59PM -0700, James Flowers wrote:
> strncpy is deprecated for use on NUL-terminated strings, as indicated in
> Documentation/process/deprecated.rst. strncpy NUL-pads the destination
> buffer and doesn't guarantee the destination buffer will be NUL
> terminated.
> 
> Signed-off-by: James Flowers <bold.zone2373@fastmail.com>
> ---
> V1 -> V2: Replaced with two argument version of strscpy
> Note: this has only been compile tested.

Reviewed-by: Simon Horman <horms@kernel.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] net/smc: Replace use of strncpy on NUL-terminated string with strscpy
  2025-09-01  3:04 [PATCH v2] net/smc: Replace use of strncpy on NUL-terminated string with strscpy James Flowers
  2025-09-01 16:03 ` Simon Horman
@ 2025-09-02  4:09 ` Dust Li
  2025-09-02  6:40 ` Mahanta Jambigi
  2025-09-02 23:00 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 6+ messages in thread
From: Dust Li @ 2025-09-02  4:09 UTC (permalink / raw)
  To: James Flowers, alibuda, sidraya, wenjia, mjambigi, tonylu, guwen,
	davem, edumazet, kuba, pabeni, horms, skhan
  Cc: linux-rdma, linux-s390, netdev, linux-kernel,
	linux-kernel-mentees

On 2025-08-31 20:04:59, James Flowers wrote:
>strncpy is deprecated for use on NUL-terminated strings, as indicated in
>Documentation/process/deprecated.rst. strncpy NUL-pads the destination
>buffer and doesn't guarantee the destination buffer will be NUL
>terminated.
>
>Signed-off-by: James Flowers <bold.zone2373@fastmail.com>

Reviewed-by: Dust Li <dust.li@linux.alibaba.com>

Best regards,
Dust

>---
>V1 -> V2: Replaced with two argument version of strscpy
>Note: this has only been compile tested.
>
> 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 76ad29e31d60..b90337f86e83 100644
>--- a/net/smc/smc_pnet.c
>+++ b/net/smc/smc_pnet.c
>@@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
> 		return -ENOMEM;
> 	new_pe->type = SMC_PNET_IB;
> 	memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
>-	strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX);
>+	strscpy(new_pe->ib_name, ib_name);
> 	new_pe->ib_port = ib_port;
> 
> 	new_ibdev = true;
>-- 
>2.50.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] net/smc: Replace use of strncpy on NUL-terminated string with strscpy
  2025-09-01  3:04 [PATCH v2] net/smc: Replace use of strncpy on NUL-terminated string with strscpy James Flowers
  2025-09-01 16:03 ` Simon Horman
  2025-09-02  4:09 ` Dust Li
@ 2025-09-02  6:40 ` Mahanta Jambigi
  2025-09-02  7:12   ` James
  2025-09-02 23:00 ` patchwork-bot+netdevbpf
  3 siblings, 1 reply; 6+ messages in thread
From: Mahanta Jambigi @ 2025-09-02  6:40 UTC (permalink / raw)
  To: James Flowers, alibuda, dust.li, sidraya, wenjia, tonylu, guwen,
	davem, edumazet, kuba, pabeni, horms, skhan
  Cc: linux-rdma, linux-s390, netdev, linux-kernel,
	linux-kernel-mentees



On 01/09/25 8:34 am, James Flowers wrote:
> strncpy is deprecated for use on NUL-terminated strings, as indicated in
> Documentation/process/deprecated.rst. strncpy NUL-pads the destination
> buffer and doesn't guarantee the destination buffer will be NUL
> terminated.
> 
> Signed-off-by: James Flowers <bold.zone2373@fastmail.com>
> ---
> V1 -> V2: Replaced with two argument version of strscpy
> Note: this has only been compile tested.
> 
>  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 76ad29e31d60..b90337f86e83 100644
> --- a/net/smc/smc_pnet.c
> +++ b/net/smc/smc_pnet.c
> @@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
>  		return -ENOMEM;
>  	new_pe->type = SMC_PNET_IB;
>  	memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
> -	strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX);
> +	strscpy(new_pe->ib_name, ib_name);

I tested your changes by creating a Software PNET ID using *smc_pnet*
tool & it works fine. Your changes are similar to ae2402b(net/smc:
replace strncpy with strscpy) commit.

Reviewed-by: Mahanta Jambigi <mjambigi@linux.ibm.com>

>  	new_pe->ib_port = ib_port;
>  
>  	new_ibdev = true;



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] net/smc: Replace use of strncpy on NUL-terminated string with strscpy
  2025-09-02  6:40 ` Mahanta Jambigi
@ 2025-09-02  7:12   ` James
  0 siblings, 0 replies; 6+ messages in thread
From: James @ 2025-09-02  7:12 UTC (permalink / raw)
  To: Mahanta Jambigi, alibuda, Dust Li, sidraya, wenjia, tonylu, guwen,
	davem, edumazet, kuba, pabeni, Simon Horman, Shuah Khan
  Cc: linux-rdma, linux-s390, netdev, linux-kernel,
	linux-kernel-mentees



On Mon, Sep 1, 2025, at 11:40 PM, Mahanta Jambigi wrote:
> On 01/09/25 8:34 am, James Flowers wrote:
>> strncpy is deprecated for use on NUL-terminated strings, as indicated in
>> Documentation/process/deprecated.rst. strncpy NUL-pads the destination
>> buffer and doesn't guarantee the destination buffer will be NUL
>> terminated.
>> 
>> Signed-off-by: James Flowers <bold.zone2373@fastmail.com>
>> ---
>> V1 -> V2: Replaced with two argument version of strscpy
>> Note: this has only been compile tested.
>> 
>>  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 76ad29e31d60..b90337f86e83 100644
>> --- a/net/smc/smc_pnet.c
>> +++ b/net/smc/smc_pnet.c
>> @@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
>>  		return -ENOMEM;
>>  	new_pe->type = SMC_PNET_IB;
>>  	memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
>> -	strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX);
>> +	strscpy(new_pe->ib_name, ib_name);
>
> I tested your changes by creating a Software PNET ID using *smc_pnet*
> tool & it works fine. Your changes are similar to ae2402b(net/smc:
> replace strncpy with strscpy) commit.
>
> Reviewed-by: Mahanta Jambigi <mjambigi@linux.ibm.com>
>
>>  	new_pe->ib_port = ib_port;
>>  
>>  	new_ibdev = true;

Thank you for doing that test, Mahanta. Thanks to all who have reviewed so far.

Best regards,
James Flowers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] net/smc: Replace use of strncpy on NUL-terminated string with strscpy
  2025-09-01  3:04 [PATCH v2] net/smc: Replace use of strncpy on NUL-terminated string with strscpy James Flowers
                   ` (2 preceding siblings ...)
  2025-09-02  6:40 ` Mahanta Jambigi
@ 2025-09-02 23:00 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-09-02 23:00 UTC (permalink / raw)
  To: James
  Cc: alibuda, dust.li, sidraya, wenjia, mjambigi, tonylu, guwen, davem,
	edumazet, kuba, pabeni, horms, skhan, linux-rdma, linux-s390,
	netdev, linux-kernel, linux-kernel-mentees

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Sun, 31 Aug 2025 20:04:59 -0700 you wrote:
> strncpy is deprecated for use on NUL-terminated strings, as indicated in
> Documentation/process/deprecated.rst. strncpy NUL-pads the destination
> buffer and doesn't guarantee the destination buffer will be NUL
> terminated.
> 
> Signed-off-by: James Flowers <bold.zone2373@fastmail.com>
> 
> [...]

Here is the summary with links:
  - [v2] net/smc: Replace use of strncpy on NUL-terminated string with strscpy
    https://git.kernel.org/netdev/net-next/c/d250f14f5f07

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-09-02 23:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-01  3:04 [PATCH v2] net/smc: Replace use of strncpy on NUL-terminated string with strscpy James Flowers
2025-09-01 16:03 ` Simon Horman
2025-09-02  4:09 ` Dust Li
2025-09-02  6:40 ` Mahanta Jambigi
2025-09-02  7:12   ` James
2025-09-02 23:00 ` patchwork-bot+netdevbpf

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).