net/smc: Replace use of strncpy on NUL-terminated string with strscpy
Subsystems (5)
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
@@ -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
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.Signed-off-by James Flowers <[email protected]>---
V1 -> V2: Replaced with two argument version of strscpy
Note: this has only been compile tested.
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.Signed-off-by James Flowers <[email protected]>
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@@ -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
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.Signed-off-by James Flowers <[email protected]>---
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
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
-0new_pe->ib_port = ib_port; new_ibdev = true;
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.Signed-off-by James Flowers <[email protected]>---
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
-0net/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
Reviewed-by Mahanta Jambigi <[email protected]>Quoted 3 lines
net/smc/smc_pnet.c +0
-0new_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
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.Signed-off-by James Flowers <[email protected]>[...]
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