freebsd-dev/lib/libc/string
Dimitry Andric aa8d126847 Fix a possible segfault in wcsxfrm(3) and wcsxfrm_l(3).
If the length of the source wide character string, passed in via the
"size_t n" parameter, is set to zero, the function should only return
the required length for the destination wide character string.  In this
case, it should *not* attempt to write to the destination, so the "dst"
parameter is permitted to be NULL.

However, when the internally called _collate_wxfrm() function returns an
error, such as when using the "C" locale, as a fallback wcscpy(3) or
wcsncpy(3) are used.  But if the input length is zero, wcsncpy(3) will
be called with a length of -1!  If the "dst" parameter is NULL, this
will immediately result in a segfault, or if "dst" is a valid pointer,
it will most likely result in unexpectedly overwritten memory.

Fix this by explicitly checking for an input length greater than zero,
before calling wcsncpy(3).

Note that a similar situation does not occur in strxfrm(3), the plain
character version of this function, as it uses strlcpy(3) for the error
case.  The strlcpy(3) function does not write to the destination if the
input length is zero.

MFC after:	1 week
2019-08-07 20:13:43 +00:00
..
bcmp.3 Add timingsafe_bcmp and timingsafe_memcmp. 2016-08-14 23:38:50 +00:00
bcmp.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
bcopy.3 Fix spelling. 2015-08-24 01:53:18 +00:00
bcopy.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
bstring.3
bzero.3 Update bzero(3) manpage to following the Posix Standard. 2015-08-24 01:51:10 +00:00
bzero.c
ffs.3 Document bitset(9) 2015-10-17 19:55:58 +00:00
ffs.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
ffsl.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
ffsll.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
fls.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
flsl.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
flsll.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
index.3
Makefile.inc Document memset_s(3). memset_s(3) is defined in 2018-02-16 05:48:45 +00:00
memccpy.3
memccpy.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
memchr.3
memchr.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
memcmp.3 Add timingsafe_bcmp and timingsafe_memcmp. 2016-08-14 23:38:50 +00:00
memcmp.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
memcpy.3 Add notes about overlapping copies. 2017-11-13 17:04:44 +00:00
memcpy.c
memmem.3 libc: Use musl's O(n) memmem and strstr 2017-03-18 00:51:39 +00:00
memmem.c Avoid OOB reads in memmem(3). 2018-10-15 20:20:57 +00:00
memmove.3
memmove.c
memrchr.c
memset_s.c Improve standard compliance for memset_s() and abort_handler_s(). 2017-08-12 15:18:17 +00:00
memset.3 Provide set_constraint_handler_s(3) man page. 2018-08-19 14:39:57 +00:00
memset.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
stpcpy.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
stpncpy.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
strcasecmp.3
strcasecmp.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strcasestr.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strcat.3 Add notes about overlapping copies. 2017-11-13 17:04:44 +00:00
strcat.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strchr.3
strchr.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strchrnul.c Remove "all rights reserved" on files where I have copyright. 2018-05-09 17:06:52 +00:00
strcmp.3
strcmp.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strcoll.3
strcoll.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
strcpy.3 strcpy.3: Improve legibility and clarity 2018-06-06 20:09:21 +00:00
strcpy.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strcspn.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
strdup.3 strdup.3: Document standardization in POSIX 2018-06-06 21:32:49 +00:00
strdup.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strerror.3
strerror.c Fix WITHOUT_NLS build after r342551. 2018-12-28 16:08:49 +00:00
string.3
strlcat.c
strlcpy.3 Make it clear that the "size" argument is for the dst string. 2016-02-26 22:14:19 +00:00
strlcpy.c
strlen.3 Don't put multiple names on a single .Nm line. This fixes apropos(1) 2018-04-17 09:05:46 +00:00
strlen.c Remove "All rights reserved" from my files. 2018-05-10 06:41:08 +00:00
strmode.3
strmode.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strncat.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strncmp.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strncpy.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strndup.c Replace strndup with OpenBSD's implementation. 2015-08-26 23:28:10 +00:00
strnlen.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
strnstr.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strpbrk.3
strpbrk.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strrchr.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strsep.3 strsep.3: don't silently ignore errors 2018-05-28 18:29:15 +00:00
strsep.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strsignal.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strspn.3
strspn.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
strstr.3
strstr.c libc: update strstr implementation to match musl 2019-04-09 15:52:18 +00:00
strtok.3 Add a standards compliance note for strtok_r as suggested by cpercival. 2016-01-22 20:36:03 +00:00
strtok.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
strxfrm.3
strxfrm.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
swab.3
swab.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
Symbol.map Implement the memset_s(3) function as specified by the C11 ISO/IEC 2017-03-30 04:57:26 +00:00
timingsafe_bcmp.3 Add timingsafe_bcmp and timingsafe_memcmp. 2016-08-14 23:38:50 +00:00
timingsafe_bcmp.c Add timingsafe_bcmp and timingsafe_memcmp. 2016-08-14 23:38:50 +00:00
timingsafe_memcmp.c Add timingsafe_bcmp and timingsafe_memcmp. 2016-08-14 23:38:50 +00:00
wcpcpy.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
wcpncpy.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcscasecmp.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcscat.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcschr.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcscmp.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
wcscoll.3
wcscoll.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcscpy.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcscspn.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcsdup.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcslcat.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcslcpy.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcslen.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcsncasecmp.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcsncat.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcsncmp.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
wcsncpy.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
wcsnlen.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcspbrk.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcsrchr.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcsspn.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcsstr.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
wcstok.3
wcstok.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
wcswidth.3
wcswidth.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
wcsxfrm.3
wcsxfrm.c Fix a possible segfault in wcsxfrm(3) and wcsxfrm_l(3). 2019-08-07 20:13:43 +00:00
wmemchr.3
wmemchr.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wmemcmp.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wmemcpy.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wmemmove.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wmemset.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00