Commit Graph

42430 Commits

Author SHA1 Message Date
Adhemerval Zanella 2097879f6e math: Fix UB in ldbl-128ibm setpayload 2025-05-08 10:18:12 -03:00
Adhemerval Zanella d044eb659e math: Fix UB in ldbl-128ibm llroundl 2025-05-08 10:18:12 -03:00
Adhemerval Zanella 623bd741fb math: Fix UB in ldbl-128ibm lrintl 2025-05-08 10:18:09 -03:00
Adhemerval Zanella 673776c7be math: Fix UB in ldbl-128ibm llrintl 2025-05-08 09:34:19 -03:00
Adhemerval Zanella 5ae9c869b0 math: Fix UB in ldbl-128 __ieee754_rem_pio2l
UBSAN: Undefined behaviour in ../sysdeps/ieee754/ldbl-128ibm/e_rem_pio2l.c:254:27 left shift of 325455441821696 by 23 cannot be represented in type 'long int'
2025-05-08 09:34:17 -03:00
Adhemerval Zanella 00411d0fad math: Fix UB in roundevenf_finite
On powerpc64le tanf tests show:

UBSAN: Undefined behaviour in ../sysdeps/ieee754/flt-32/math_config.h:105:11 passing zero to __builtin_ctz()
2025-05-08 09:34:15 -03:00
Adhemerval Zanella 8e684b1ddc math: Fix UB in ldbl-128ibm ilogb
UBSAN: Undefined behaviour in ../sysdeps/ieee754/ldbl-128ibm/e_ilogbl.c:45:37 left shift of 4611686018427387904 by 1 cannot be represented in type 'long int'
2025-05-08 09:34:10 -03:00
Adhemerval Zanella 98b2b7be53 math: Fix UB in flt-32 rint
UBSAN: Undefined behaviour in ../sysdeps/ieee754/flt-32/s_rintf.c:46:4 left shift of 1 by 31 cannot be represented in type 'int'
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 0a933c9bf7 math: Fix UB in flt-32 nearbyint
UBSAN: Undefined behaviour in ../sysdeps/ieee754/flt-32/s_nearbyintf.c:53:4 left shift of 1 by 31 cannot be represented in type 'int'
2025-05-08 09:25:49 -03:00
Adhemerval Zanella ae54df4654 math: Fix UB on dbl-64 rint
UBSAN: Undefined behaviour in ../sysdeps/ieee754/dbl-64/s_rint.c:53:4 left shift of 1 by 63 cannot be represented in type 'long long int'
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 48557d36a0 math: Fix UB in dbl-64 lrint
UBSAN: Undefined behaviour in ../sysdeps/ieee754/dbl-64/s_lrint.c:99:30 left shift of 1048576 by 11 cannot be represented in type 'long int'
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 5b97637011 math: Fix UB in ldbl-128 setpayload
UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/s_setpayloadl_main.c:47:34 shift exponent 16431 is too large for 64-bit type 'long long unsigned int'
2025-05-08 09:25:49 -03:00
Adhemerval Zanella b91a135500 math: Fix UB in flt-32 and dbl-64 significand
On x86_64:

$ math/test-float-significand
testing float (without inline functions)
UBSAN: Undefined behaviour in ./s_significand_template.c:31:45 negation of 2147483648 cannot be represented in type 'int'
2025-05-08 09:25:49 -03:00
Adhemerval Zanella d3c633b03d math: Fix UB in ldbl-96 sinl 2025-05-08 09:25:49 -03:00
Adhemerval Zanella 8175ef182f math: Fix UB in ldbl-128 powl
testing _Float128 (without inline functions)
UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/e_powl.c:439:11 left shift of 4294953849 by 16 cannot be represented in type 'int'
2025-05-08 09:25:49 -03:00
Adhemerval Zanella c1ffff3c53 math: Fix UB in ldbl-128 roundl
$ math/test-float128-cospi
testing _Float128 (without inline functions)
UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/s_roundl.c:75:30 left shift of 1 by 63 cannot be represented in type 'long long int'
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 9dc7be063e math: Fix UB in __ieee754_rem_pio2l 2025-05-08 09:25:49 -03:00
Adhemerval Zanella ae41adf241 math: Fix UB in ldbl-128 rintl
UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/s_rintl.c:60:4 left shift of 1 by 63 cannot be represented in type 'long int'
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 9f65638ed1 math: Fix UB in ldbl-128 nearbyintl
UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/s_nearbyintl.c:61:4 left shift of 1 by 63 cannot be represented in type 'long int'
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 1d60cac326 math: Fix UB in lroundl
UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/s_lroundl.c:72:32 left shift of 562949953421312 by 14 cannot be represented in type 'long int'
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 712ff06cd6 math: Fix UB in ldbl-128 lrintl
$ math/test-float128-llrint

UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/s_llrintl.c:83:31 left shift of 281474976710656 by 15 cannot be represented in type 'long long int'
Aborted

UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/s_lrintl.c:111:30 left shift of 281474976710656 by 15 cannot be represented in type 'long int'
Aborted
2025-05-08 09:25:49 -03:00
Adhemerval Zanella c1540fcdde math: Fix UB in ldbl-128 llrintl
testing _Float128 (without inline functions)
UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/s_llrintl.c:83:31 left shift of 281474976710656 by 15 cannot be represented in type 'long long int'
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 8d83145f7f math: Fix UB on ldbl-128 fmodl 2025-05-08 09:25:49 -03:00
Adhemerval Zanella e5387c9493 math: Fix UB in ldbl-128 llroundl
Building with --enable-ubasn triggers:

$ math/test-float128-llround
testing _Float128 (without inline functions)
UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/s_llroundl.c:65:37 left shift of 562949953421312 by 14 cannot be represented in type 'long long int'
Aborted
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 4c3292f634 math: Fix UB in ldbl-96 setayloadl
The code can shift the 1ULL for value larger than 32 depending of
the exponent value.  Building with ubsan triggers:

$ math/test-ldouble-setpayload
testing long double (without inline functions)
UBSAN: Undefined behaviour in ../sysdeps/ieee754/ldbl-96/s_setpayloadl_main.c:48:32 shift exponent 16414 is too large for 32-bit type 'unsigned int'
2025-05-08 09:25:49 -03:00
Adhemerval Zanella ebaeeb8112 math: Fix UB on ldbl-96 remquol
Building with --enable-ubasn triggers:

$ math/test-ldouble-pow
testing long double (without inline functions)
UBSAN: Undefined behaviour in ../sysdeps/ieee754/ldbl-96/s_roundl.c:75:28 left shift of 1 by 31 cannot be represented in type 'int'
2025-05-08 09:25:49 -03:00
Adhemerval Zanella c949920ef6 math: Fix UB on lroundl
Building with --enable-ubasn triggers:

$ math/test-ldouble-pow
testing long double (without inline functions)
UBSAN: Undefined behaviour in ../sysdeps/ieee754/ldbl-96/s_roundl.c:75:28 left shift of 1 by 31 cannot be represented in type 'int'
Aborted
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 51a2a92502 math: Fix UB on llroundl
Building with --enable-ubasn triggers:

UBSAN: Undefined behaviour in ../sysdeps/ieee754/ldbl-96/s_llroundl.c:70:25 left shift of 4294967296 by 31 cannot be represented in type 'long long int'

The right shift is undefined if value overflow, but code is assuming
an arithmetic shift.
2025-05-08 09:25:49 -03:00
Adhemerval Zanella b7c497474b x86: Fix UB in isnanl
Building with --enable-ubasn triggers:

$ math/test-ldouble-roundeven
UBSAN: Undefined behaviour in ../sysdeps/ieee754/ldbl-96/s_roundl.c:75:28 left shift of 1 by 31 cannot be represented in type 'int'

Also adds the inputs that triggers it on isnan testcase.
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 258ea84448 x86: Fix UB in isinfl
Building with --enable-ubasn triggers:

$ math/test-ldouble-isinf
UBSAN: Undefined behaviour in ../sysdeps/x86/fpu/s_isinfl.c:25:8 negation of 2147483648 cannot be represented in type 'int'

Also move the isinfl implementation to sysdeps/x86 and remove the
sysdeps/x86_64 version.
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 6deb970376 gmon: Fix UB in sprofil
UBSAN: Undefined behaviour in ../sysdeps/posix/sprofil.c:272:16 variable length array bound evaluates to non-positive value 0

Move the VLA to after the porfile stop condition (where size might
be zero).
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 6465987859 gmon: Fix UB in tst-sprofil.c
UBSAN: Undefined behaviour in tst-sprofil.c:140:6 unsigned integer overflow: 2432902008176640000 + 7812407968270641256 cannot be represened in type 'long int'

Use unsigned types for the fibonacci.
2025-05-08 09:25:49 -03:00
Adhemerval Zanella da2b1f328e string: Remove UB on ffs/ffsll
Building with ubsan on 32 bit architecture, tst-ffs shows:

ffsll(0x4000000000000000) as expected 63
UBSAN: Undefined behaviour in ffsll.c:37:34 negation of 9223372036854775808 cannot be represented in type 'long long int'

Since the idea is to isolate the least significant bit, use unsigned
types.
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 9ae7611c80 string: Fix UB on test-strrchr
UBSAN: Undefined behaviour in test-strrchr.c💯35 unsigned integer overflow: 1804289383 * 846930886 cannot be represened in type 'long int'

Use int64_t operations instead.
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 180cbc0cc9 sysvipc: Fix UB on time64 time support
Building with ubsan on 32 bit architecture without 64 bit time_t
as default, it shows:

UBSAN: Undefined behaviour in ../sysdeps/unix/sysv/linux/msgctl.c:180:45 left shift of 3935167480 by 32 cannot be represented in type 'long long int'

Add a new macro, IPC_HILO, to handle this transparently by using
unsigned shifts.
2025-05-08 09:25:49 -03:00
Adhemerval Zanella fed92e28c5 nptl: xfail tst-cleanup2 when building with ubsan
The test explicit uses UB (sprintf (NULL, ...) to triggers a SIGSEGV
from libc and check with the pthread cleanup are correctly called.

With ubsan enable, it triggers:

UBSAN: Undefined behaviour in Xprintf_buffer_write.c:39:7 null pointer passed as argument 1, nonnull attribute declared at unknown:0:0

Which is a memcpy call with NULL argument.
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 967c9fd3eb stdio: Fix test-printf-ldbl-compat.c build with ubsan
On powercp64le with --enable-ubsan the build fails with:

In file included from ../include/bits/stdio2.h:1,
                 from ../libio/stdio.h:967,
                 from ../include/stdio.h:14,
                 from ../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.c:21,
                 from ../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ieee128.c:1:
In function ‘vfprintf’,
    inlined from ‘do_test_call_varg’ at ../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.c:56:3:
../libio/bits/stdio2.h:166:10: error: null format string [-Werror=format-overflow=]
  166 |   return __vfprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt, __ap);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘vsnprintf’,
    inlined from ‘do_test_call_varg’ at ../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.c:68:3:
../libio/bits/stdio2.h💯10: error: null format string [-Werror=format-truncation=]
  100 |   return __builtin___vsnprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  101 |                                     __glibc_objsize (__s), __fmt, __ap);
      |                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘fprintf’,
    inlined from ‘do_test_call_rarg.constprop’ at ../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.c:104:3:
../libio/bits/stdio2.h:111:10: error: null format string [-Werror=format-overflow=]
  111 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  112 |                         __va_arg_pack ());
      |                         ~~~~~~~~~~~~~~~~~
In function ‘printf’,
    inlined from ‘do_test_call_rarg.constprop’ at ../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.c:108:3:
../libio/bits/stdio2.h:118:10: error: null format string [-Werror=format-overflow=]
  118 |   return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘snprintf’,
    inlined from ‘do_test_call_rarg.constprop’ at ../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-ldbl-compat.c:112:3:
../libio/bits/stdio2.h:68:10: error: null format string [-Werror=format-truncation=]
   68 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   69 |                                    __glibc_objsize (__s), __fmt,
      |                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   70 |                                    __va_arg_pack ());
      |                                    ~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
2025-05-08 09:25:49 -03:00
Adhemerval Zanella 319de14379 stdio: Fix test-printf-chk-ldbl-compat build with ubsan
On powercp64le with --enable-ubsan the build fails with:

../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-chk-ldbl-compat.c: In function ‘do_test_call_varg’:
../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-chk-ldbl-compat.c:60:3: error: null format string [-Werror=format-overflow=]
   60 |   __vfprintf_chk (stream, 1, format, args);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-chk-ldbl-compat.c:66:3: error: null format string [-Werror=format-overflow=]
   66 |   __vprintf_chk (1, format, args);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-chk-ldbl-compat.c:72:3: error: null format string [-Werror=format-truncation=]
   72 |   __vsnprintf_chk (string, 79, 1, 127, format, args);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-chk-ldbl-compat.c: In function ‘do_test_call_rarg.constprop’:
../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-chk-ldbl-compat.c:111:3: error: null format string [-Werror=format-overflow=]
  111 |   __fprintf_chk (stdout, 1, format, ld, d);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-chk-ldbl-compat.c:115:3: error: null format string [-Werror=format-overflow=]
  115 |   __printf_chk (1, format, ld, d);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../sysdeps/ieee754/ldbl-128ibm-compat/test-printf-chk-ldbl-compat.c:119:3: error: null format string [-Werror=format-truncation=]
  119 |   __snprintf_chk (string, 79, 1, 127, format, ld, d);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2025-05-08 09:25:44 -03:00
Adhemerval Zanella 9b3a4a701d stdio-common: Fix UB on stdio-common/vfprintf-process-arg.c
On i686 debug/tst-sprintf-fortify-unchecked triggers:

UBSAN: Undefined behaviour in vfprintf-process-arg.c:41:57 negation of 9223372036854775808 cannot be represented in type 'long long int'
2025-05-08 09:25:44 -03:00
Adhemerval Zanella 612ba930aa nss: Fix tst-nss-hash UB
UBSAN: Undefined behaviour in tst-nss-hash.c:49:8 variable length array bound evaluates to non-positive value 0
2025-05-08 09:25:44 -03:00
Adhemerval Zanella 6a180670f8 nss: Fix UB on test-netdb
The gethostname is defined as not accepting NULL arguments, so
use a minimal size for initial call.
2025-05-08 09:25:44 -03:00
Adhemerval Zanella dc4b8962cb stdlib: Fix tst-makecontext3 UB
UBSAN: Undefined behaviour in tst-makecontext3.c:164:40 left shift of 1794341827 by 1 cannot be represented in type 'int'
2025-05-08 09:25:44 -03:00
Adhemerval Zanella 4b23aedb1b linux: Fix UB on tst-sched-setattr.c
UBSAN: Undefined behaviour in ../sysdeps/unix/sysv/linux/tst-sched_setattr.c:86:5 null pointer passed as argument 2, nonnull attribute declared at unknown:0:0
2025-05-08 09:25:39 -03:00
Adhemerval Zanella e4b9aa70a7 string: Fix UB on tesf-ffs
UBSAN: Undefined behaviour in test-ffs.c:48:3 left shift of 1 by 31 cannot be represented in type 'int'
2025-05-08 09:25:39 -03:00
Adhemerval Zanella 8ee1efc90d stdlib: Fix UB in tst-limits.c
UBSAN: Undefined behaviour in tst-limits.c:14:16 left shift of 1 by 63 cannot be represented in type 'long long int'
2025-05-08 09:25:39 -03:00
Adhemerval Zanella ba3e3ae80b stdlib: Adapt tst-environ to ubsan
The test explicits checks for passing a null argument to a
function with argument nonnull attribute.
2025-05-08 09:25:35 -03:00
Adhemerval Zanella afe9efb47c stdlib: Fix UB on strtod FIX 2025-05-07 14:21:21 -03:00
Adhemerval Zanella a48d71c81f math: Rewrite ldbl-128 isnan
With ubsan, test-float128-cabs triggers:

UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/s_isnanl.c:29:30 negation of 9223372036854775808 cannot be represented in type 'long int'

Rewrite with simplified version.
2025-05-07 14:21:21 -03:00
Adhemerval Zanella 61ad23190e math: Fix UB in float128 atan2
UBSAN: Undefined behaviour in ../sysdeps/ieee754/float128/../ldbl-128/e_atan2l.c:68:9 unsigned integer overflow: 9223372036854775808 - 4611404543450677248 cannot be represened in type 'long int'
2025-05-07 14:21:21 -03:00
Adhemerval Zanella 8beaca2512 math: Fix UB in test-canonical-ldbl-96.c
UBSAN: Undefined behaviour in ../sysdeps/ieee754/ldbl-96/test-canonical-ldbl-96.c:97:7 left shift of 1 by 31 cannot be represented in type 'int'
2025-05-07 14:21:21 -03:00