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
88EXPORT_SYMBOL(strcpy);88EXPORT_SYMBOL(strcpy);
89#endif89#endif
90 90
91#ifndef __HAVE_ARCH_STRNCPY
92char *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}
104EXPORT_SYMBOL(strncpy);
105#endif
106
107#ifdef __BIG_ENDIAN91#ifdef __BIG_ENDIAN
108# define ALLBUTLAST_BYTE_MASK (~255ul)92# define ALLBUTLAST_BYTE_MASK (~255ul)
109#else93#else