* [PATCH net-next v2] net: ipconfig: Replace strncpy with strscpy in ic_proto_name
@ 2025-11-26 22:08 Thorsten Blum
2025-11-29 4:30 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-11-26 22:08 UTC (permalink / raw)
To: david laight, David S. Miller, David Ahern, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman
Cc: Thorsten Blum, netdev, linux-kernel
strncpy() is deprecated [1] for NUL-terminated destination buffers
because it does not guarantee NUL termination. Replace it with strscpy()
to ensure the destination buffer is always NUL-terminated and to avoid
any additional NUL padding.
Although the identifier buffer has 252 usable bytes, strncpy() copied
only up to 251 bytes to the zero-initialized buffer, relying on the last
byte to act as an implicit NUL terminator. Switching to strscpy() avoids
this implicit behavior and does not use magic numbers.
The source string is also NUL-terminated and satisfies the
__must_be_cstr() requirement of strscpy().
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Changes in v2:
- Use strscpy() to avoid unnecessary padding (David)
- Update patch title and description accordingly
- Link to v1: https://lore.kernel.org/lkml/20251126111358.64846-1-thorsten.blum@linux.dev/
---
net/ipv4/ipconfig.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index 22a7889876c1..019408d3ca2c 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -1690,7 +1690,8 @@ static int __init ic_proto_name(char *name)
*v = 0;
if (kstrtou8(client_id, 0, dhcp_client_identifier))
pr_debug("DHCP: Invalid client identifier type\n");
- strncpy(dhcp_client_identifier + 1, v + 1, 251);
+ strscpy(dhcp_client_identifier + 1, v + 1,
+ sizeof(dhcp_client_identifier) - 1);
*v = ',';
}
return 1;
--
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next v2] net: ipconfig: Replace strncpy with strscpy in ic_proto_name
2025-11-26 22:08 [PATCH net-next v2] net: ipconfig: Replace strncpy with strscpy in ic_proto_name Thorsten Blum
@ 2025-11-29 4:30 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-11-29 4:30 UTC (permalink / raw)
To: Thorsten Blum
Cc: david.laight, davem, dsahern, edumazet, kuba, pabeni, horms,
netdev, linux-kernel
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Wed, 26 Nov 2025 23:08:05 +0100 you wrote:
> strncpy() is deprecated [1] for NUL-terminated destination buffers
> because it does not guarantee NUL termination. Replace it with strscpy()
> to ensure the destination buffer is always NUL-terminated and to avoid
> any additional NUL padding.
>
> Although the identifier buffer has 252 usable bytes, strncpy() copied
> only up to 251 bytes to the zero-initialized buffer, relying on the last
> byte to act as an implicit NUL terminator. Switching to strscpy() avoids
> this implicit behavior and does not use magic numbers.
>
> [...]
Here is the summary with links:
- [net-next,v2] net: ipconfig: Replace strncpy with strscpy in ic_proto_name
https://git.kernel.org/netdev/net-next/c/ff736a286116
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] 2+ messages in thread
end of thread, other threads:[~2025-11-29 4:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-26 22:08 [PATCH net-next v2] net: ipconfig: Replace strncpy with strscpy in ic_proto_name Thorsten Blum
2025-11-29 4:30 ` 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).