Skip to contentSkip to conversation

net/smc: Replace use of strncpy on NUL-terminated string with strscpy

PATCH Applied James Flowers 5 participants 6 messages Sep 1, 2025 – Sep 2, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net/smc: Replace use of strncpy on NUL-terminated string with strscpy

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.

---
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(-)
net/smc/smc_pnet.c +1 -1
index 76ad29e31d60..b90337f86e83 100644
@@ -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;
Signature · 1 line
2.50.1
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · James Flowers

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.

---
V1 -> V2: Replaced with two argument version of strscpy
Note: this has only been compile tested.

maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to James Flowers
Quoted 6 lines · James Flowers

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.

Best regards,
Dust

Quoted 22 lines

---
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(-)
net/smc/smc_pnet.c +1 -1
index 76ad29e31d60..b90337f86e83 100644
@@ -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;
Signature · 1 line
2.50.1
maintainer Reviewed-by on v2 1/1
#3 lore raw
In reply to James Flowers
Quoted 18 lines · James Flowers

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.

---
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(-)
net/smc/smc_pnet.c +0 -0
index 76ad29e31d60..b90337f86e83 100644

net/smc/smc_pnet.c static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name, · line 453

Quoted 5 lines
net/smc/smc_pnet.c +1 -1
@@ -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.

Quoted 3 lines
net/smc/smc_pnet.c +0 -0
 	new_pe->ib_port = ib_port;
 
 	new_ibdev = true;
author
#4 lore raw
Quoted 29 lines · Mahanta Jambigi
Quoted 18 lines · James Flowers

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.

---
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(-)
net/smc/smc_pnet.c +0 -0
index 76ad29e31d60..b90337f86e83 100644

net/smc/smc_pnet.c static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name, · line 453

Quoted 5 lines
net/smc/smc_pnet.c +1 -1
@@ -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.

Quoted 5 lines
Quoted 3 lines
net/smc/smc_pnet.c +0 -0
 	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

#5 lore raw
In reply to James Flowers
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · 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.

[...]

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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html