]> Gentwo Git Trees - linux/.git/commit
net: ipconfig: Replace strncpy with strscpy in ic_proto_name
authorThorsten Blum <thorsten.blum@linux.dev>
Wed, 26 Nov 2025 22:08:05 +0000 (23:08 +0100)
committerJakub Kicinski <kuba@kernel.org>
Sat, 29 Nov 2025 04:19:16 +0000 (20:19 -0800)
commitff736a286116d462a4067ba258fa351bc0b4ed80
tree2ae2496b4a45d8046b3f728879a2114a231a7554
parent840a64710e6d26589d4bdcc99c765037a7c5c95f
net: ipconfig: Replace strncpy with strscpy in ic_proto_name

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
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://patch.msgid.link/20251126220804.102160-2-thorsten.blum@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/ipconfig.c