Skip to contentSkip to conversation

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

PATCH Superseded James Flowers 1 participant 2 messages Aug 31, 2025

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

---
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..5cfde2b9cad8 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, IB_DEVICE_NAME_MAX);
 	new_pe->ib_port = ib_port;
 
 	new_ibdev = true;
Signature · 1 line
2.50.1
author
#1 lore raw
Quoted 25 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.

---
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..5cfde2b9cad8 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, IB_DEVICE_NAME_MAX);
 	new_pe->ib_port = ib_port;
 
Quoted 3 lines

new_ibdev = true;

Signature · 1 line
2.50.1

Please disregard. Sorry, just noticed I should have used the two argument version of strscpy. I will send a V2.