linux/lib/test_fortify
Kees Cook 079a028d63 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>
2026-06-18 16:39:31 -07:00
..
.gitignore fortify: refactor test_fortify Makefile to fix some build problems 2024-08-15 09:26:02 -07:00
Makefile kbuild: require gcc-8 and binutils-2.30 2025-04-30 21:53:35 +02:00
read_overflow-memchr_inv.c
read_overflow-memchr.c
read_overflow-memcmp.c
read_overflow-memscan.c
read_overflow2_field-memcpy.c
read_overflow2_field-memmove.c fortify: Detect struct member overflows in memmove() at compile-time 2022-02-13 16:50:06 -08:00
read_overflow2-memcmp.c
read_overflow2-memcpy.c
read_overflow2-memmove.c
test_fortify.h
test_fortify.sh fortify: Cleanup temp file also on non-successful exit 2026-01-14 19:49:55 -08:00
write_overflow_field-memcpy.c
write_overflow_field-memmove.c fortify: Detect struct member overflows in memmove() at compile-time 2022-02-13 16:50:06 -08:00
write_overflow_field-memset.c fortify: Detect struct member overflows in memset() at compile-time 2022-02-13 16:50:06 -08:00
write_overflow-memcpy.c
write_overflow-memmove.c
write_overflow-memset.c
write_overflow-strcpy-lit.c
write_overflow-strcpy.c
write_overflow-strscpy.c