Skip to contentSkip to conversation

nvmet: replace strncpy with strscpy

PATCH Superseded Marcelo Moreira 2 participants 2 messages Apr 1, 2025 – Apr 3, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmet: replace strncpy with strscpy

strncpy() is deprecated due to its lack of NULL-termination guarantees and unnecessary zero-padding of the destination buffer. Use strscpy() instead.

---
 drivers/nvme/target/discovery.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/discovery.c +1 -1
index df7207640506..c06f3e04296c 100644
@@ -119,7 +119,7 @@ static void nvmet_format_discovery_entry(struct nvmf_disc_rsp_page_hdr *hdr,
 	memcpy(e->trsvcid, port->disc_addr.trsvcid, NVMF_TRSVCID_SIZE);
 	memcpy(e->traddr, traddr, NVMF_TRADDR_SIZE);
 	memcpy(e->tsas.common, port->disc_addr.tsas.common, NVMF_TSAS_SIZE);
-	strncpy(e->subnqn, subsys_nqn, NVMF_NQN_SIZE);
+	strscpy(e->subnqn, subsys_nqn, NVMF_NQN_SIZE);
 }
 
 /*
Signature · 1 line
2.49.0
#1 lore raw
Quoted 3 lines · Marcelo Moreira

strncpy() is deprecated due to its lack of NULL-termination guarantees and unnecessary zero-padding of the destination buffer. Use strscpy() instead.

Nothing explains here why it is deprecated and why the replacement is better. And why using memcpy or a seq_buf wasn't considered.

Quoted 1 line

And these kinds of links are actively harmful as the point a commercial entity that can be taken down or changed at any time. Don't do that.