summaryrefslogtreecommitdiff
path: root/lib/string.c
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-03-23 04:27:25 +0300
committerKees Cook <kees@kernel.org>2026-06-19 02:39:31 +0300
commit079a028d6327e68cfa5d38b36123637b321c19a7 (patch)
treed6bed2ef9b0f5969d1105f010d8b4a8804a13f61 /lib/string.c
parent58c4ce8cd6cd1fbf1bca2e1d1f42f9e2899fa934 (diff)
downloadlinux-079a028d6327e68cfa5d38b36123637b321c19a7.tar.xz
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. Link: https://github.com/KSPP/linux/issues/90 [1] Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'lib/string.c')
-rw-r--r--lib/string.c16
1 files changed, 0 insertions, 16 deletions
diff --git a/lib/string.c b/lib/string.c
index b632c71df1a5..45ca1cfe0184 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -88,22 +88,6 @@ char *strcpy(char *dest, const char *src)
EXPORT_SYMBOL(strcpy);
#endif
-#ifndef __HAVE_ARCH_STRNCPY
-char *strncpy(char *dest, const char *src, size_t count)
-{
- char *tmp = dest;
-
- while (count) {
- if ((*tmp = *src) != 0)
- src++;
- tmp++;
- count--;
- }
- return dest;
-}
-EXPORT_SYMBOL(strncpy);
-#endif
-
#ifdef __BIG_ENDIAN
# define ALLBUTLAST_BYTE_MASK (~255ul)
#else