freebsd-nq/lib/libc
Stefan Eßer d106f982a5 qsort.c: prevent undefined behavior
Mark Milliard has detected a case of undefined behavior with the LLVM
UBSAN. The mandoc program called qsort with a==NULL and n==0, which is
allowed by the POSIX standard. The qsort() in FreeBSD did not attempt
to perform any accesses using the passed pointer for n==0, but it did
add an offset to the pointer value, which is undefined behavior in
case of a NULL pointer. This operation has no adverse effects on any
achitecture supported by FreeBSD, but could be caught in more strict
environments.

After some discussion in the freebsd-current mail list, it was
concluded that the case of a==NULL and n!=0 should still be caught by
UBSAN (or cause a program abort due to an illegal access) in order to
not hide errors in programs incorrectly invoking qsort().

Only the the case of a==NULL and n==0 should be fixed to not perform
the undefined operation on a NULL pointer.

This commit makes qsort() exit before reaching the point of
potentially undefined behvior for the case n==0, but does not test
the value of a, since the result will not depend on whether this
pointer is NULL or an actual pointer to an array if n==0.

The issue found by Mark Milliard in the whatis command has been
reported to the upstream (OpenBSD) and has already been patched
there.

MFC after:	1 week
2022-01-13 11:09:38 +01:00
..
aarch64 libc: Remove _get_tp() and _set_tp(). 2021-12-09 13:23:26 -08:00
amd64 libc: Remove _get_tp() and _set_tp(). 2021-12-09 13:23:26 -08:00
arm libc: Remove _get_tp() and _set_tp(). 2021-12-09 13:23:26 -08:00
capability Fix a few mandoc issues 2020-10-09 19:12:44 +00:00
compat-43 Adjust history, info source from v1's manuals 2019-09-04 13:44:46 +00:00
db tools/build: Don't redefine open() for the linux bootstrap 2021-08-02 14:33:23 +01:00
gdtoa Remove sparc64 specific parts of libc. 2020-02-26 18:55:09 +00:00
gen libc: Teak comment about mips 2022-01-10 10:15:15 -07:00
gmon
i386 libc: Remove _get_tp() and _set_tp(). 2021-12-09 13:23:26 -08:00
iconv libc: Fix "harmless" iconv one-byte overread 2021-12-21 22:47:38 +00:00
include libc: Remove _get_tp() and _set_tp(). 2021-12-09 13:23:26 -08:00
inet
isc
locale libc/locale: Fix races between localeconv(3) and setlocale(3) 2021-09-17 10:47:46 -04:00
md
nameser Bounds check again after advancing cp, otherwise we have a possible 2019-09-05 19:35:30 +00:00
net libc: Fix build with -DNS_REREAD_CONF. 2021-12-29 17:01:05 -05:00
nls Implement strerror_l(). 2020-12-16 09:02:09 +00:00
posix1e acl_delete_entry(): remove write-only variable 2021-11-29 17:39:51 +02:00
powerpc libc: Remove _get_tp() and _set_tp(). 2021-12-09 13:23:26 -08:00
powerpc64 libc: Remove _get_tp() and _set_tp(). 2021-12-09 13:23:26 -08:00
powerpcspe [PowerPC] [PowerPCSPE] Fix multiple issues in fpsetmask(). 2021-02-28 21:11:29 -06:00
quad Add casts and L suffixes to libc quad support, to work around various 2020-02-17 20:14:59 +00:00
regex libc: Fix regexec when sizeof(char *) > sizeof(long) 2021-12-23 16:38:10 +00:00
resolv res_init: remove unused inet_makeaddr with IN_LOOPBACKNET 2021-11-09 09:33:48 -06:00
riscv libc: Remove _get_tp() and _set_tp(). 2021-12-09 13:23:26 -08:00
rpc libc clnt_com_create: relock rpcsoc_lock earlier when port is obtained from portmapper 2022-01-09 07:36:06 +02:00
secure libc: ssp: sprinkle around some __dead2 2021-09-30 23:55:17 -05:00
softfloat libc: use standard LF line endings, not CRLF 2021-04-03 16:20:07 -04:00
stdio libc/stdio/vfwscanf.c::convert_wstring(): wcp0 is write-only 2021-11-29 17:39:51 +02:00
stdlib qsort.c: prevent undefined behavior 2022-01-13 11:09:38 +01:00
stdtime tzcode: Implement timezone change detection 2021-09-12 03:07:58 +00:00
string memcpy.3: remove BUGS section allowing overlapping strings 2021-08-24 09:58:10 -04:00
sys Clarify the description of the EINTEGRITY error in intro(2). 2021-12-28 16:39:46 -08:00
tests libc/tests/stdlib/dynthr_mod/dynthr_mod.c: mark dummy as used 2021-11-29 17:39:51 +02:00
uuid uuid(3): Document return values 2021-11-19 03:58:34 -05:00
x86 Make CPU_SET macros compliant with other implementations 2021-12-30 12:20:32 +01:00
xdr typo: s/impelmentation/implementation/. 2020-02-07 15:14:29 +00:00
yp Increase the size of the send and receive buffers for YP client rpc 2019-09-16 06:42:01 +00:00
libc_nossp.ldscript
libc.ldscript
Makefile mips: remove libc 2021-12-31 00:14:53 -07:00
Makefile.depend Update Makefile.depend files 2019-12-11 17:37:53 +00:00
Makefile.depend.options Update libssp paths in various Makefile.depend* files 2020-01-06 18:15:55 +00:00
Versions.def Create namespace for the symbols added during 14-CURRENT cycle. 2021-07-15 19:40:28 +03:00