opnsense-src/lib/libc/string
Warner Losh 02ebbc781f swab: Fix implementation to support overlapping copies
A number of image processing packages assume that swab() can handle to
and from being the same. However, POSIX.1 states that overlapping
buffers produces undefined results. Our old implementation would produce
coherent results, but the recent change to the musl-inspired code does
not. Since there's complaints in the forums for these image processing
packages for musl and now FreeBSD, update the algorithm to just read a
word at a time and bswap16 the results. All FreeBSD's architecutres
support unaligned access in userland, and swab is not used in the kernel
(g_part_apm has its own copy), so opt for even simpler code that's
easier to understand. This makes the overlapping behavior match i386 again,
since its assembler routine for swab handles overlapping correctly.

PR: 283698
Sponsored by: Netflix
Reviewed by:	nwhitehorn
Differential Revision:	https://reviews.freebsd.org/D48259
2025-01-06 16:46:05 -07:00
..
bcmp.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
bcmp.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
bcopy.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
bcopy.c Prepare the system for _FORTIFY_SOURCE 2024-05-13 00:23:50 -05:00
bstring.3 manuals: Fix "unusual .Xr" warnings with a script 2024-10-15 17:18:14 -03:00
bzero.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
bzero.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
ffs.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
ffs.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
ffsl.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
ffsll.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
fls.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
flsl.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
flsll.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
index.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
Makefile.inc lib/libc/string: add memset_explicit() for compliance with C23 2024-11-14 23:10:00 +01:00
memccpy.3 contrib/mandoc: add -isoC-2024 and -svid1 to mdoc(7) 2024-10-26 20:11:02 +02:00
memccpy.c lib/libc/string: document restrict qualification of memccpy() arguments 2023-12-25 14:59:50 +01:00
memchr.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
memchr.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
memcmp.3 memcmp.3: Clarify return value 2024-11-20 12:15:11 -05:00
memcmp.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
memcpy.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
memcpy.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
memmem.3 libc: indicate existing functions that are POSIX 2024 2024-11-14 21:32:20 -05:00
memmem.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
memmove.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
memmove.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
mempcpy.c include: ssp: don't shadow the mempcpy builtin 2024-07-16 00:12:28 -05:00
memrchr.c Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
memset.3 lib/libc/string: add memset_explicit() for compliance with C23 2024-11-14 23:10:00 +01:00
memset.c Prepare the system for _FORTIFY_SOURCE 2024-05-13 00:23:50 -05:00
memset_explicit.c lib/libc/string: apply SSP hardening and tests to memset_explicit 2024-11-14 23:10:00 +01:00
memset_s.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
stpcpy.c Prepare the system for _FORTIFY_SOURCE 2024-05-13 00:23:50 -05:00
stpncpy.c Prepare the system for _FORTIFY_SOURCE 2024-05-13 00:23:50 -05:00
strcasecmp.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strcasecmp.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strcasestr.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
strcat.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strcat.c Prepare the system for _FORTIFY_SOURCE 2024-05-13 00:23:50 -05:00
strchr.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strchr.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
strchrnul.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
strcmp.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strcmp.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strcoll.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strcoll.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
strcpy.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strcpy.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strcspn.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
strdup.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strdup.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strerror.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strerror.c include: ssp: round out fortification of current set of headers 2024-07-13 00:16:24 -05:00
string.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strlcat.c include: ssp: round out fortification of current set of headers 2024-07-13 00:16:24 -05:00
strlcpy.3 strlcpy/strlcat: Remove references to snprintf 2023-10-27 10:13:50 -06:00
strlcpy.c include: ssp: round out fortification of current set of headers 2024-07-13 00:16:24 -05:00
strlen.3 strnlen(3): add HISTORY 2024-03-15 14:52:47 -07:00
strlen.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
strmode.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strmode.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strncat.c Prepare the system for _FORTIFY_SOURCE 2024-05-13 00:23:50 -05:00
strncmp.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strncpy.c include: ssp: round out fortification of current set of headers 2024-07-13 00:16:24 -05:00
strndup.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
strnlen.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
strnstr.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strpbrk.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strpbrk.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strrchr.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strsep.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strsep.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strsignal.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strspn.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strspn.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
strstr.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strstr.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
strtok.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strtok.c lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strverscmp.3 libc: fix history for strverscmp(3) and versionsort(3) 2023-08-31 14:52:31 +03:00
strverscmp.c libc: Add strverscmp(3) and versionsort(3) 2022-08-25 03:29:03 +03:00
strxfrm.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
strxfrm.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
swab.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
swab.c swab: Fix implementation to support overlapping copies 2025-01-06 16:46:05 -07:00
Symbol.map lib/libc/string: add memset_explicit() for compliance with C23 2024-11-14 23:10:00 +01:00
timingsafe_bcmp.3 timingsafe_bcmp(3) was MFC'ed to 11.1 2024-01-05 20:54:13 -08:00
timingsafe_bcmp.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
timingsafe_memcmp.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
wcpcpy.c include: ssp: fortify <wchar.h> 2024-07-13 00:16:25 -05:00
wcpncpy.c include: ssp: fortify <wchar.h> 2024-07-13 00:16:25 -05:00
wcscasecmp.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
wcscat.c include: ssp: fortify <wchar.h> 2024-07-13 00:16:25 -05:00
wcschr.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
wcscmp.c sccs: Manual changes 2023-11-26 22:23:58 -07:00
wcscoll.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
wcscoll.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
wcscpy.c include: ssp: fortify <wchar.h> 2024-07-13 00:16:25 -05:00
wcscspn.c Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:42 -06:00
wcsdup.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
wcslcat.c include: ssp: fortify <wchar.h> 2024-07-13 00:16:25 -05:00
wcslcpy.c include: ssp: fortify <wchar.h> 2024-07-13 00:16:25 -05:00
wcslen.c Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:42 -06:00
wcsncasecmp.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
wcsncat.c include: ssp: fortify <wchar.h> 2024-07-13 00:16:25 -05:00
wcsncmp.c sccs: Manual changes 2023-11-26 22:23:58 -07:00
wcsncpy.c include: ssp: fortify <wchar.h> 2024-07-13 00:16:25 -05:00
wcsnlen.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
wcspbrk.c Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:42 -06:00
wcsrchr.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
wcsspn.c Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:42 -06:00
wcsstr.c lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
wcstok.3 Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:10 -06:00
wcstok.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
wcswidth.3 Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:10 -06:00
wcswidth.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
wcsxfrm.3 lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
wcsxfrm.c libc: Purge unneeded cdefs.h 2023-11-01 16:44:30 -06:00
wmemchr.3 wmemchr(3): fix prototypes for wcpcpy() and wcpncpy() 2024-03-21 10:40:08 +02:00
wmemchr.c Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:42 -06:00
wmemcmp.c Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:42 -06:00
wmemcpy.c include: ssp: fortify <wchar.h> 2024-07-13 00:16:25 -05:00
wmemmove.c include: ssp: fortify <wchar.h> 2024-07-13 00:16:25 -05:00
wmempcpy.c include: ssp: fortify <wchar.h> 2024-07-13 00:16:25 -05:00
wmemset.c include: ssp: fortify <wchar.h> 2024-07-13 00:16:25 -05:00