freebsd-src/lib
Karl Tomlinson e75a1bbc23 pow,powf(3),__ieee754_rem_pio2(f): Avoid negative integer left shift UB
A compiler clever enough to know that z is positive with a non-zero
biased exponent could, for example, optimize away the scalbnf(z,n) in
pow() because behavior for left shift of negative values is undefined.
`n` is negative when y*log2(|x|) < -0.5.  i.e. |x^y| < sqrt(0.5)

The intended behavior for operator<< in this code is to shift the two's
complement representation of the first operand.

In the pow() functions, the result is added to the IEEE 754 exponent of
z = 2^y'.  n may be negative enough to underflow the biased IEEE 754
exponent below zero, which is manifested in the sign bit of j
(which would correspond to the IEEE 754 sign bit).

The conversion from uint32_t to int32_t for out-of-int32_t-range values
is implementation defined.  The assumed behavior of interpreting the
uint32_t value as a two's complement representation of a signed value
is already assumed in many parts of the code, such as uses of
GET_FLOAT_WORD() with signed integers.

This code passes all the current tests, and makes some out of tree
fuzzing tests pass again rather than hit UB (detailed in the commentary
of the pull request).

Signed-off-by: Karl Tomlinson <karlt+@karlt.net>
Reviewed by: imp, steve kargl, dim
Pull Request: https://github.com/freebsd/freebsd-src/pull/1137
2024-04-23 14:04:07 -06:00
..
atf Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
clang Merge llvm-project release/18.x llvmorg-18.1.4-0-ge6c3289804a6 2024-04-20 16:02:57 +02:00
csu csu: add crtbrand.o dependency on sys/param.h 2024-01-31 15:40:27 -05:00
flua flua: Add hash module 2024-02-15 20:59:23 -07:00
geom geli.8: minor proofreading 2024-04-22 15:54:56 -06:00
googletest Fix GoogleTest 1.14.0 import 2023-08-18 19:33:58 -07:00
lib9p dirdeps: Update Makefile.depend* files with empty contents 2023-10-29 17:01:04 -04:00
lib80211 Purge more stray embedded $FreeBSD$ strings 2023-09-25 07:54:56 -07:00
libalias Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libarchive libarchive: add two missing package files to libarchive tests 2024-04-17 09:58:32 +02:00
libauditd Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libbe libbe(3): history: fix 2024-04-09 22:01:10 -06:00
libbearssl bearssl: Make shared library link 2024-02-20 20:31:41 -07:00
libbegemot Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libblacklist Track upstream project rename in contrib/blocklistd 2023-11-03 16:53:04 -04:00
libblocksruntime Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libbluetooth Remove $FreeBSD$: one-line nroff pattern 2023-08-16 11:55:15 -06:00
libbsddialog dirdeps: Update Makefile.depend* files with empty contents 2023-10-29 17:01:04 -04:00
libbsdstat libbsdstat: Fix typo in bsdstat.h 2024-02-13 16:53:35 +08:00
libbsm Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libbsnmp Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libbz2 Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libc libc printf_render_errno(): do not use strerror() 2024-04-23 22:44:07 +03:00
libc++ Merge llvm-project main llvmorg-18-init-18359-g93248729cfae 2024-04-06 22:13:49 +02:00
libc++experimental Merge llvm-project main llvmorg-18-init-15088-gd14ee76181fb 2024-04-06 22:11:55 +02:00
libc_nonshared Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libcalendar Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:10 -06:00
libcam lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libcapsicum Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:10 -06:00
libcasper libcasper: fix cap_rights_init usage 2024-02-14 22:33:24 -05:00
libcbor Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libclang_rt Merge llvm-project main llvmorg-18-init-15088-gd14ee76181fb 2024-04-06 22:11:55 +02:00
libcom_err Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libcompat libcompat: silence -Wdeprecated-non-prototype 2024-02-06 20:32:46 +01:00
libcompiler_rt libcompiler_rt Makefile.inc: update _Float16/__bf16 checks 2024-04-17 22:20:47 +02:00
libcrypt lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libcuse Remove $FreeBSD$: one-line nroff pattern 2023-08-16 11:55:15 -06:00
libcxxrt libcxxrt: align more with libc/Makefile 2024-04-22 21:28:51 +01:00
libdevctl lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libdevdctl libdevdctl: Fix typo (triple S) 2023-12-27 20:24:30 -07:00
libdevinfo lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libdevstat lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libdiff diff: Integrate libdiff from OpenBSD GoT. 2024-03-27 11:03:33 +01:00
libdl Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libdpv lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libdwarf Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libedit lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
libefivar lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libelf Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libelftc Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libevent1 Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libexecinfo lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libexpat MFV: expat 2.6.0. 2024-02-17 14:04:14 -08:00
libfdt libfdt: Make an internal FDT library available 2024-03-21 01:05:05 -04:00
libfetch libfetch: parse scheme://domain:/ correctly 2024-03-25 16:11:42 -04:00
libfido2 libfido2: update to 1.13.0 2023-09-19 13:06:12 -04:00
libfigpar lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libgcc_eh libgcc_{eh,s}: restore __*_frame_info symbols post llvm18 2024-04-19 22:56:13 +01:00
libgcc_s libgcc_s: expose __divmoddi4 on i386 2024-04-19 22:56:13 +01:00
libgeom lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libgpio libgpio: Fix type mismatch for gpio_pin_[gs]et 2023-11-14 18:34:21 -08:00
libgssapi Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:10 -06:00
libiconv_modules lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libifconfig libifconfig: Fix bridge status member list 2023-12-21 16:50:27 +01:00
libipsec libipsec: make const-correct 2024-04-22 22:36:34 -06:00
libipt Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libiscsiutil lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libjail libjail: Guard against programmer error in jailparam_export() 2024-02-04 17:52:30 -05:00
libkiconv Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:10 -06:00
libkvm lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libldns Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
liblua dirdeps: Remove $FreeBSD$ 2023-11-26 15:47:54 -05:00
liblutok Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
liblzma Backport export of lzma_mt_block_size symbol. 2024-04-04 23:39:33 -07:00
libmagic libmagic: Use HOST_CC when compiling hostprog used by build 2024-03-27 19:18:43 -04:00
libmd lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libmemstat lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libmilter Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libmixer mixer(3): Do not hardcode "/dev/mixer" 2024-02-12 13:00:05 +02:00
libmp Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:10 -06:00
libmt lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libnetbsd lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libnetgraph lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libnetmap libnetmap: remove interface name validation 2023-12-21 14:43:57 +00:00
libnv lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libomp Merge llvm-project main llvmorg-18-init-15088-gd14ee76181fb 2024-04-06 22:11:55 +02:00
libopenbsd lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libopencsd Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libpam package: move cron into its own package 2024-04-22 22:36:35 -06:00
libpathconv Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:10 -06:00
libpcap dirdeps: Fix libpcap Makefile.depend.options 2023-11-17 11:34:57 -05:00
libpe Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libpfctl libpfctl: fix incorrect labels copy 2024-03-22 09:00:05 +01:00
libpjdlog lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libpmc libpmc: Import AMD Zen 4 PMU events 2024-04-20 11:54:04 -04:00
libpmcstat lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libproc lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libprocstat inpcb: fully retire inp_ppcb pointer 2024-03-29 12:18:32 -07:00
libradius lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libregex dirdeps: Update Makefile.depend* files with empty contents 2023-10-29 17:01:04 -04:00
librpcsec_gss librpcsec_gss: don't export non-existant symbols 2024-04-16 22:14:21 +01:00
librpcsvc lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
librss lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
librt lib{c,rt}: use libsys.h for __sys_* declerations 2024-04-16 17:48:07 +01:00
librtld_db lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libsbuf lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libsdp Remove $FreeBSD$: one-line nroff pattern 2023-08-16 11:55:15 -06:00
libsecureboot libsecureboot do not report expected unverified files 2024-02-12 14:35:01 -08:00
libsm Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libsmb Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libsmdb Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libsmutil Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libsqlite3 Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libssp lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libssp_nonshared Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libstats dirdeps: Update Makefile.depend* files with empty contents 2023-10-29 17:01:04 -04:00
libstdbuf Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:10 -06:00
libstdthreads libstdthreads: destroy mutexattr in mtx_init() 2024-02-04 13:50:56 +02:00
libsys sigqueue(2): Document __SIGQUEUE_TID 2024-04-23 19:51:10 +03:00
libsysdecode libsysdecode use MKTABLES_INCLUDEDIR 2024-03-21 11:55:56 -07:00
libtacplus lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libtelnet lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
libthr Add test for pthread_sigqueue(3) 2024-04-23 19:51:31 +03:00
libthread_db lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libucl Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libufs lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libugidfw Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:10 -06:00
libulog lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libunbound unbound: Vendor import 1.19.3 2024-03-17 01:57:42 -06:00
libusb libusb(3): Fix link in comment 2024-02-13 16:55:54 +08:00
libusbhid lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libutil login_cap.h: Remove LOGIN_DEFPRI 2024-01-29 22:58:10 +01:00
libveriexec lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
libvgl lib/libvgl/main.c: remove an extra semicolon 2024-02-02 18:35:01 -07:00
libvmmapi libvmmapi: Conditionalize compilation of some functions 2024-04-10 11:17:56 -04:00
libwrap Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libxo dirdeps: Update Makefile.depend* files with empty contents 2023-10-29 17:01:04 -04:00
liby lib: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
libypclnt Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libz dirdeps: Update/fix Makefile.depend* for toolchain 2023-11-26 20:50:13 -05:00
libzstd libzstd: Explicitly define ZSTD_DISABLE_ASM 2023-08-22 21:01:03 +01:00
msun pow,powf(3),__ieee754_rem_pio2(f): Avoid negative integer left shift UB 2024-04-23 14:04:07 -06:00
ncurses ncurses: serialize the tinfo build a little bit 2024-01-23 23:00:36 -06:00
nss_tacplus nss_tacplus: Provide dummy setpwent(), getpwent_r(), endpwent(). 2023-08-31 07:49:57 +00:00
ofed Trim various $FreeBSD$ 2023-10-10 10:34:43 -07:00
tests Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
Makefile arm64: Connect bhyve and libvmmapi to the build 2024-04-10 11:17:56 -04:00
Makefile.inc Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00