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.
Showing the changes to lib/string.c (1 of 8 files). Show all
Unified · Split
| @@ -88,22 +88,6 @@ char *strcpy(char *dest, const char *src) · 87 unmodified lines | |||
| 88 | EXPORT_SYMBOL(strcpy); | 88 | EXPORT_SYMBOL(strcpy); |
| 89 | #endif | 89 | #endif |
| 90 | 90 | ||
| 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 | |||
| 107 | #ifdef __BIG_ENDIAN | 91 | #ifdef __BIG_ENDIAN |
| 108 | # define ALLBUTLAST_BYTE_MASK (~255ul) | 92 | # define ALLBUTLAST_BYTE_MASK (~255ul) |
| 109 | #else | 93 | #else |