History

string: Remove strncpy() from the kernel

strncpy() has been a persistent source of bugs due to its ambiguous intended usage and frequently counter-intuitive semantics: it may not NUL-terminate the destination, and it unconditionally zero-pads to the full length, which isn't always needed. All former callers have been migrated[1] to: - strscpy() for NUL-terminated destinations - strscpy_pad() for NUL-terminated destinations needing zero-padding - strtomem_pad() for non-NUL-terminated fixed-width fields - memcpy_and_pad() for bounded copies with explicit padding - memcpy() for known-length copies Remove the generic implementation, its declaration, the FORTIFY_SOURCE wrapper, and associated tests.

Kees Cook committed 7 months ago

Commit 079a0281 parent 58c4ce88 files · +28 −160Browse files

Showing the changes to lib/string.c (1 of 8 files). Show all

Unified · Split

lib/string.c+0−16
@@ -88,22 +88,6 @@ char *strcpy(char *dest, const char *src) · 87 unmodified lines
8888 EXPORT_SYMBOL(strcpy);
8989 #endif
9090
91−#ifndef __HAVE_ARCH_STRNCPY
92−char *strncpy(char *dest, const char *src, size_t count)
93−{
94− char *tmp = dest;
95−
96− while (count) {
97− if ((*tmp = *src) != 0)
98− src++;
99− tmp++;
100− count--;
101− }
102− return dest;
103−}
104−EXPORT_SYMBOL(strncpy);
105−#endif
106−
10791 #ifdef __BIG_ENDIAN
10892 # define ALLBUTLAST_BYTE_MASK (~255ul)
10993 #else