Top stories
Linux removes the strncpy API after six years and 362 patches
- Category: Linux/Kernel
- Status: confirmed
- Sources: Phoronix, discussion
- Summary: Work queued for the Linux 7.2 merge window eliminates the last in-kernel users of
strncpy, completing a six-year hardening effort that took about 362 commits.strncpywas a persistent source of bugs because of counter-intuitive NUL-termination semantics and redundant zero-filling. Kernel code now usesstrscpyfor NUL-terminated destinations,strscpy_padfor NUL-terminated with zero padding,strtomem_padfor non-NUL-terminated fixed-width fields,memcpy_and_padfor bounded copies with explicit padding, or plainmemcpyfor known-length copies. - Comments: HN commenters note the replacement APIs encode intent that the original
strncpyleft ambiguous, and discuss whether the destination string functions should have been split this way from the start. - Why it matters: Removing a whole class of error-prone string handling from a codebase the size of the kernel reduces a long-standing buffer-handling bug surface across every subsystem.